在Tkinter中关闭窗口的函数
import tkinter
class App():
def __init__(self):
self.root = Tkinter.Tk()
button = Tkinter.Button(self.root, text = 'root quit', command=self.quit)
button.pack()
self.root.mainloop()
def quit(self):
self.root.destroy
app = App()
我该怎么做才能让我的 quit
函数关闭窗口呢?
4 个回答
3
def exit(self):
self.frame.destroy()
exit_btn=Button(self.frame,text='Exit',command=self.exit,activebackground='grey',activeforeground='#AB78F1',bg='#58F0AB',highlightcolor='red',padx='10px',pady='3px')
exit_btn.place(relx=0.45,rely=0.35)
这个方法对我有效,可以在点击退出按钮时关闭我的Tkinter框架。
4
在编程中,有时候我们需要处理一些数据,比如从一个地方获取数据,然后把它放到另一个地方。这就像把水从一个杯子倒到另一个杯子一样。
有些时候,我们会遇到一些问题,比如数据的格式不对,或者我们想要的数据不在我们想象的地方。这就需要我们仔细检查一下,看看是不是哪里出了错。
在这个过程中,我们可能会用到一些工具和方法,帮助我们更好地管理和处理这些数据。就像在厨房里,我们会用不同的工具来切菜、煮饭一样。
总之,处理数据就像做饭一样,需要耐心和细心,才能做出美味的菜肴。
class App():
def __init__(self):
self.root = Tkinter.Tk()
button = Tkinter.Button(self.root, text = 'root quit', command=self.quit)
button.pack()
self.root.mainloop()
def quit(self):
self.root.destroy()
app = App()
72
def quit(self):
self.root.destroy()
在 destroy
后面加上括号,这样才能调用这个方法。
当你使用 command=self.root.destroy
时,你是把这个方法传给 Tkinter.Button
,但没有加括号,因为你希望 Tkinter.Button
保存这个方法,以便将来可以调用,而不是在按钮创建的时候就立刻执行。
但是,当你定义 quit
方法时,你需要在这个方法的内容里调用 self.root.destroy()
,因为到那时这个方法已经被调用了。