[Python] How to exit from Python using a Tkinter Button?

There are two functions you should use to quit a window:

  • destroy()
  • quit()

Here you have the code using one of the two:

import Tkinter
import tkMessageBox
import time
import sys

def endProgam():
    # top.quit()
    top.destroy()        

top = Tkinter.Tk()

B = Tkinter.Button(top, text = "Hello", command = endProgam)
B.pack()
top.mainloop()

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *