2011-09-05 22 views
1

爲什麼這個錯誤,爲什麼不tk屬性?爲什麼在Python中錯誤不是tk屬性?

錯誤:

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\Tkinter.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' 

守則:

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

有什麼不對?

回答

1

在此代碼:

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

的第一個參數的按鈕應該被Tkinter的容器(例如,根窗口,或一幀)的一個實例。根據http://code.google.com/p/childreneditor/source/browse/trunk/editor-new.py,self是ScrolledText的一個實例,它不能包含其他小部件。

嘗試將self更改爲frm

相關問題