python - 为什么错误不是python中的tk属性?

标签 python tkinter

为什么会出现这个错误,为什么不是 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

出了什么问题?

最佳答案

在此代码中:

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

Button 的第一个参数应该是 Tkinter 容器的实例(例如根窗口或框架)。根据http://code.google.com/p/childreneditor/source/browse/trunk/editor-new.py , self 是 ScrolledText 的实例,不能包含其他小部件。

尝试将 self 更改为 frm

关于python - 为什么错误不是python中的tk属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7310073/

相关文章:

python - 如何在Python中向量化这个for循环?

python - 网格未按预期工作 python Tkinter

Python tkinter 标签

python - TFIDF 计算困惑

python - 使用 aiohttp 嵌套 "async with"

python - 对 Pandas 数据框进行 Mann–Whitney U 检验

Python;无法调用列表框

python - 移动功能 Tkinter 出错

python - 如何从 Tkinter 中的条目获取输入以用于另一个窗口中使用的函数?

python - 使用 xlrd 和 xlwt 编辑现有的 excel 工作簿和工作表