这是我的服务器脚本,在没有 GUI 的情况下运行它时,只有启动方法才能正常工作,但是当运行整个脚本并按下启动按钮时,它只是冻结并且没有响应,并且文本窗口上没有任何内容
from Tkinter import *
import socket
import sys
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.text = Text(self, width = 35, height = 5, wrap = WORD)
self.text.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.submit_button = Button(self, text='start', command = self.start)
self.submit_button.grid(row = 2, column = 0, sticky = W)
def start(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.text.insert(0.0, 'Server started!\n' )
self.s.bind(('',1080))
self.s.listen(10)
while True:
sc, address = self.s.accept()
i=1
f = open('file_'+ str(i)+".txt",'wb') #open in binary
i=i+1
while (True):
l = sc.recv(1024)
while (l):
print l
f.write(l)
f.flush()
f.close()
sc.close()
root = Tk()
root.title("Server")
root.geometry("500x250")
app = Application(root)
root.mainloop()