我是 python 的新手,我尝试了一个 Gui 应用程序,但它导致的错误如下:
错误:
Traceback (most recent call last):
File "C:\Python27\aqw.py", line 22, in <module>
app = myproject(None,None)
File "C:\Python27\aqw.py", line 8, in __init__
self.button()
File "C:\Python27\aqw.py", line 13, in button
button = Tkinter.Button(self,text=u"Succedd !")
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2106, in __init__
Widget.__init__(self, master, 'button', cnf, kw)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2027, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2000, in _setup
if not master:
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1826, in __getattr__
return getattr(self.tk, attr)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1826, in __getattr__
return getattr(self.tk, attr)
请帮助我修复我的代码!
我的代码:
import Tkinter
from Tkinter import *
class myproject(Tkinter.Tk):
def __init__(self,parent, master):
self.button()
self.checkbox()
self.radiobutton()
def button(self):
#add quit button
button = Tkinter.Button(self,text=u"Succedd !")
button.grid(column=3,row=1)
def checkbox(self):
checkbox = Checkbutton(self, text = "Music", variable = CheckVar2)
checkbox.grid(column=3,row=1)
def radiobutton(self):
radiobutton = Tkinter.Radiobutton(self, text="Option 2", variable=var, value=2)
app = myproject(None,None)
app.mainloop()
请帮忙!我们将不胜感激!
最佳答案
你需要调用父类(super class)的__init__
方法:
class myproject(Tkinter.Tk):
def __init__(self, parent, master):
Tkinter.Tk.__init__(self) # <----
self.button()
self.checkbox()
self.radiobutton()
...
除此之外,还有 undefined variable CheckVar2
、var
。
关于python - 返回 __get attr__ 的 Tkinter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25702512/