Deelaka
Deelaka

Reputation: 13719

How to hard quit a Tkinter program

My Python program consists of two parts, one gets user credentials through an Tkinter and passes it to the other script which then processes them.

It works fine but the only problem is that although my GUI passes data and then the processing script starts its work, The GUI starts not-responding and causes havoc as it freezes until the download completes (which could potentially take hours)

I create an object of the Interface class in the processing script by importing the GUI script

root = Tk.Tk()
root.title('Coursera-dl')
root.geometry("345x100")
app = GUI.Interface(root)
app.mainloop()

This is my GUI script's destruct method defined in a Class which is executed automatically after the data has been received by the processing script: However when the user clicks 'OK' the GUI freezes and doesn't exit and If I force quit it, the processing script also ends as python.exe is terminated

*code*
....................................
def destruct(self):
    if tkMessageBox.askokcancel(title=None,message='Download would start upon closing the Interface, If any changes are to be made to the credentials Please do so by selecting Cancel'):
        self.quit()

How can I make my program so that when the user clicks on 'OK' the GUI quits safely and the processing script does its work

Upvotes: 1

Views: 599

Answers (1)

Serial
Serial

Reputation: 8043

root.quit() just Bypasses the root.mainloop() i.e root.mainloop() will still be running in background if quit() command is executed.

Use root.destroy()

this will stop root.mainloop() itself but it wont close the python program and everything will still be ran just without the GUI

Upvotes: 3

Related Questions