[python]點選按鈕關閉式窗

練習如何點選按鈕後,關閉整個tkinter式窗。

import Tkinter as tk
class Mainapplication(tk.Frame):
	def __init__(self,master):
		self.master=master
		tk.Frame.__init__(self,master)
		self.pack()
		self.createwidget()
	def createwidget(self):
		self.label = tk.Label(self,text="hello world")
		self.label.pack()
		self.button = tk.Button(self,text="CLOSE",command=self.closeme)
		self.button.pack()
	def closeme(self):
		self.master.destroy()
	


if __name__=='__main__':
	root = tk.Tk()
	app = Mainapplication(master=root)
	root.mainloop()

在這裡要記錄的事情是,要利用master才能關閉整個視窗成式,如果是destroy frame的話,只會將畫面清除掉而已。

self.master=master

 

By Jsy