2017-02-19 50 views
0

我想知道如何獲得它,所以單擊按鈕時tkinter的窗口將關閉,任何幫助表示讚賞。以下是我的代碼的一部分。如何在點擊時關閉Tkinter窗口?

def ynumber_chosen(): 
    class number: 
     def __init__ (self, root): 
      root.title('Picking a row') 
      root.minsize(width = 3, height = 225) 
      root.maxsize(width = 3, height = 225) 

      label = Label(root, text = "Pick a row") 

      self.button1 = Button(root, text = "1", height = 3, width = 7, command = ynumber1) 
      self.button1.grid(row = 0, column = 1) 
      self.button1 = Button(root, text = "2", height = 3, width = 7, command = ynumber2) 
      self.button1.grid(row = 0, column = 3) 
      self.button1 = Button(root, text = "3", height = 3, width = 7, command = ynumber3) 
      self.button1.grid(row = 2, column = 1) 
      self.button1 = Button(root, text = "4", height = 3, width = 7, command = ynumber4) 
      self.button1.grid(row = 2, column = 3) 
      self.button1 = Button(root, text = "5", height = 3, width = 7, command = ynumber5) 
      self.button1.grid(row = 3, column = 1) 
      self.button1 = Button(root, text = "6", height = 3, width = 7, command = ynumber6) 
      self.button1.grid(row = 3, column = 3) 
      self.button1 = Button(root, text = "7", height = 3, width = 7, command = ynumber7) 
      self.button1.grid(row = 4, column = 1) 


    root = Tk() 
    app1 = number(root) 
    mainloop() 
+1

任何基本的tkinter教程都應該包括這個。你有什麼嘗試?只是谷歌搜索「tkinter退出」給出了足夠的結果。 – Lafexlos

回答

0

要銷燬的窗口,你需要調用root.destroy()在點擊命令ynumberX()方法:

def ynumberX(): 
    """Do something with number here""" 
    root.destroy 

您可以通過root無論是作爲類變量或參數ynumberX()方法(關於該主題參見: http://effbot.org/zone/tkinter-callbacks.htm

相關問題