如何解决在 Tkinter 中使用 Button 对象时出现错误?
开发过程中遇到在 Tkinter 中使用 Button 对象时出现错误的问题如何解决?下面主要结合日常开发的经验,给出你关于在 Tkinter 中使用 Button 对象时出现错误的解决方法建议,希望对你解决在 Tkinter 中使用 Button 对象时出现错误有所启发或帮助;问题描述
运行此代码时:
import tkinter as tk
class MyApplication(tk.Tk):
def __init__(self,*args,**kwargs):
super().__init__(*args,**kwargs)
self.Title('Programma')
self.geometry('500x400')
self.button = tk.button(self,text='Execute',command=self.fun)
self.button.grID(row=0,column=4,stick=tk.W)
def fun(self):
print('Hello')
app = MyApplication()
app.mainloop()
我收到以下错误:
Traceback (most recent call last): file "C:/Users/Andrea/Desktop/hfhfhg.py",line 17,in <module>
app = MyApplication() file "C:/Users/Andrea/Desktop/hfhfhg.py",line 10,in __init__
self.button = tk.button(self,command=self.fun) file "C:\WPy64-3910\python-3.9.1.amd64\lib\tkinter\__init__.py",line 2346,in __getattr__
return getattr(self.tk,attr) AttributeError: '_tkinter.tkapp' object has no attribute 'fun'
我知道代码对于 GUI 来说不是最佳的,但我想了解 Tkinter 如何在不使用框架对象的情况下工作。请问你能帮我吗?
尚未找到解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)