如何解决在 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 举报,一经查实,本站将立刻删除。