mercredi 15 juin 2016

Python - Why is my Tkinter window not closing on self.destroy?

I am currently creating a little program which inserts Tkinter Entry boxes into Google Calendar (after all different kind of checks ofcourse). That part is not the problem. Since I am running a terminal at the same time that I don't want to 'hold' during the Tkinter window is open.

When I close the window using

def quit(self):
    self.thread.stop()
    self.destroy()

All the parts of the window disappear, but the window stays on screen.

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

I use this funciton to create the class:

def main(thread):

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

The myThread class.

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()

Can anybody tell me if I missed something that would make the window close properly. The thread is closed after calling the self.quit()

Aucun commentaire:

Enregistrer un commentaire