为什么错误不是python中的tk属性?
为什么会出现这个错误,为什么不是 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
有什么问题吗?
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\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'
Code on:
http://code.google.com/p/childreneditor/source/browse/trunk/editor-new.py
What is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此代码中:
Button 的第一个参数应该是 Tkinter 容器的实例(例如根窗口或框架)。根据 http://code.google.com/p /childreneditor/source/browse/trunk/editor-new.py,self是ScrolledText的一个实例,它不能包含其他小部件。
尝试将
self
更改为frm
。In this code:
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
tofrm
.