ncmathsadist
ncmathsadist

Reputation: 4889

Python 3 does not give a clean exit

This code does not give a clean exit when the Exit button is clicked. Instead, it hangs, leaaving the dead GUI. Hw can we fix this? A similar program in Python 2 behaves nicely.

from tkinter import *

import sys

root=Tk()
def quit():
    sys.exit("quitting")

frame=Frame()
frame.pack()

x=Label(root,text='Label')
x.pack()

y=Button(root,text='Button')
y.pack()

z=Button(root,text='Exit',command=quit)
z.pack()

root.mainloop()

Upvotes: 0

Views: 750

Answers (1)

Jasoon
Jasoon

Reputation: 432

def quit():
    root.destroy()

Should work...?

Upvotes: 2

Related Questions