我有一个基本的Python类,使用标准的Tkinter库创建一个窗口:
import Tkinter
class GUI(Tkinter.Tk):
def __init__(self,parent):
Tkinter.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def lock_func(self):
while 1==1:
print "blah"
def initialize(self):
self.processBtn = Tkinter.Button(self, text="Process", command=self.lock_func)
self.processBtn.pack()
app = GUI(None)
app.mainloop()
当我点击“处理”按钮时,窗口没有响应。当lock_func
正在运行时,我希望能够通过x按钮关闭程序。
Tkinter
是单线程的。你需要使用multiprocessing
模块或threading
模块来实现这个功能。 - Eric Urban