[英]How do i clear a window after pressing a button in Python Tkinter?
[英]How do I execute a command after pushing a button while also closing the window with the button in python (with tkinter)?
基本上,我想执行如下所示的命令,并同时使用2个按钮关闭窗口(无论哪种情况)。 该命令只是将变量self.switch设置为True或False,因此,如果有一种更巧妙的方法来执行此操作,而不是为每个方法编写一个新方法,那也很好。
def switchButton(self):
top = Tk()
self.a = Button(top,text="Switch", command=self.switchTrue())
self.a.pack(side=LEFT)
self.b = Button(top,text="Don't switch", command=self.switchFalse())
self.b.pack(side=RIGHT)
top.mainloop()
用一种新的方法进行操作是一种整洁的方法-您可能会想将command=lambda:self.switchTo([value])
为[value]为True或False,并希望将其交换。 您还必须将top
传递给该函数,以便可以destroy
它。
使用Tk()
destruction
是(通常)不好的做法,因为Tk()
创建了一个Tcl / Tk解释器-您实际上只想实例化一次并通常hide
其hide
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.