0
我在學習使用Tkinter的同時編寫了一些代碼,當我嘗試對它進行線程化時,它並沒有顯示窗口,但是當它運行它的主循環時卻沒有顯示。爲什麼線程不顯示Tkinter窗口?
import socket,threading,time
from Tkinter import *
class Chat(Frame):
def __init__(self,root):
Frame.__init__(self,root)
self.text=Text(self, bg='black', fg='white')
self.text.configure(state=DISABLED)
self.text.configure(state=NORMAL)
self.text.insert(END, 'hello\n'*40)
self.text.configure(state=DISABLED)
self.text.pack()
def main():
root=Tk()
root.configure(background='black')
c=Chat(root)
c.pack()
root.mainloop()
#t=threading.Thread(target=root.mainloop)
#t.start()
if __name__=='__main__':
main()
這似乎是與文本小部件的問題,但我不知道它是什麼問題。當我刪除插入行,該框出現trheading但該行,它不會出現。它有什麼問題?
在新線程中究竟想做什麼? – cdonts
@crest我想將主循環作爲一個線程來啓動,這樣我可以讓程序在tkinter窗口啓動時執行其他操作。 –
相反,您應該在主線程中運行主循環,並在程序需要執行其他操作時啓動新線程。 – cdonts