我正在读取一个文件“server.txt”,在这个文件中,我接收来自客户端的文本消息,并将它们显示在Tkinter窗口中。这是密码
from Tkinter import *
import tkMessageBox
root = Tk()
frame = Frame(root)
frame.pack()
root.geometry("500x500")
text_area = Text(frame)
text_area.pack(side=BOTTOM)
while(1):
text_area.delete(1.0, END)
fo = open("server.txt", "r")
str = fo.read(500000);
text_area.insert(END,str+'\n')
print "Read String is : ", str
# Close opend file
fo.close()
root.mainloop()
当我在命令行中打开它时,它在ubuntu中不工作
怎么做
在调用root.mainloop()之前,您将一直循环使用while函数,这意味着Tkinter窗口将永远不会弹出,但您的while语句中的print语句将被大量垃圾邮件发送
这是工作代码,使用after函数after
相关问题 更多 >
编程相关推荐