我想知道如何获得它,以便点击按钮时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()
答案 0 :(得分:0)
要销毁窗口,您需要在单击命令root.destroy()
方法中调用ynumberX()
:
def ynumberX():
"""Do something with number here"""
root.destroy
您可以将root
作为类变量或作为参数传递给ynumberX()
方法(有关该主题的更多信息,请参阅:http://effbot.org/zone/tkinter-callbacks.htm)