Tkinter错误返回__get attr__

时间:2014-09-06 16:48:53

标签: python python-2.7 tkinter

我是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()

请帮忙!答案将不胜感激!

1 个答案:

答案 0 :(得分:4)

你需要打电话给超级班级&#39; __init__方法:

class myproject(Tkinter.Tk):
   def __init__(self, parent, master):
      Tkinter.Tk.__init__(self) # <----
      self.button()
      self.checkbox()
      self.radiobutton()
   ...

除此之外,还有未定义的变量CheckVar2var