2

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

  • tkinter and threads do not mix well, see for example http://stackoverflow.com/questions/10556479/running-a-tkinter-form-in-a-separate-thread – J.J. Hakala Jun 15 '16 at 06:37
  • @shivsn That worked, thank you :) – Ricardo Umans Jun 15 '16 at 07:47
  • @J.J.Hakala So basically it would be better to only thread my original main function and then keep the `if __name__ == __main__:` looping looking for a variable to change and launch Tkinter? – Ricardo Umans Jun 15 '16 at 07:51

1 Answers1

0

instead of self.destroy() do this self.parent.destroy().

As far as my understanding we are passing tk object to the class window and it used as parent in the class.So instead of using root to create widgets we are using parent.

shivsn
  • 7,680
  • 1
  • 26
  • 33