开发者

Why error is not tk attribute in python?

开发者 https://www.devze.com 2023-04-02 07:42 出处:网络
Why this error and why not tk attribute? Error: Traceback (most recent call last): File \"editor-new.py\", line 90, in <module>

Why this error and why not tk attribute?

Error:

Traceback (most recent call last):
  File "editor-new.py", line 90, in <module>
    TextEditor().mainloop()
  File "editor-new.py", line 48, in __init__
    Button(self, text='Open', command=self.onSave).pack(side=LEFT)
  File "C:\Python27_1\lib\lib-tk\Tk开发者_开发技巧inter.py", line 2044, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "C:\Python27_1\lib\lib-tk\Tkinter.py", line 1965, in __init__
    BaseWidget._setup(self, master, cnf)
  File "C:\Python27_1\lib\lib-tk\Tkinter.py", line 1943, in _setup
    self.tk = master.tk
AttributeError: TextEditor instance has no attribute 'tk'

Code on:

http://code.google.com/p/childreneditor/source/browse/trunk/editor-new.py

What is wrong?


In this code:

Button(self, text='Open', command=self.onSave).pack(side=LEFT)

the first argument to Button should be an instance of Tkinter container (e.g. a root window, or a frame). According to http://code.google.com/p/childreneditor/source/browse/trunk/editor-new.py, self is an instance of ScrolledText, which cannot contain other widgets.

Try changing self to frm.

0

精彩评论

暂无评论...
验证码 换一张
取 消