Python - 为什么我的Tkinter窗口没有关闭self.destroy?

时间:2016-06-14 23:40:24

标签: python multithreading tkinter

我目前正在创建一个小程序,将Tkinter Entry框插入Google日历(经过所有不同类型的检查)。那部分不是问题。 由于我在同一时间运营一个终端,因此我不想“保持”#39;在Tkinter窗口期间打开。

当我使用

关闭窗口时
def quit(self):
    self.thread.stop()
    self.destroy()

窗口的所有部分都消失了,但窗口仍然在屏幕上。

class window(Frame):

def __init__(self, parent, thread):
    Frame.__init__(self, parent)   

    self.parent = parent
    self.w = 600
    self.h = 400

    self.initUI()
    self.center()
    self.thread = thread

我使用这个函数来创建类:

def main(thread):

root = Tk()
root.resizable(width=False, height=False)
app = window(root, thread)
root.mainloop()

myThread类。

class myThread(threading.Thread):
def __init__(self,threadType):
    threading.Thread.__init__(self)
    self.threadType = threadType
    self.event = threading.Event()
def stop(self):
    self.event.set()
def run(self):
    if self.threadType == "new_app":
        newappoint.main(self)
    elif self.threadType == "main":
        main()

任何人都可以告诉我,如果我遗漏了会使窗户正常关闭的东西。 调用self.quit()

后线程关闭

1 个答案:

答案 0 :(得分:0)

代替self.destroy()执行此操作self.parent.destroy()

据我所知,我们将tk对象传递给了类window,并在类中使用了parent。而不是使用root来创建小部件我们正在使用parent

相关问题