AttributeError: 'module' object has no attribute 'Tk'
AttributeError: 'module' object has no attribute 'Tk'
我开始使用 Tkinter python 库学习 GUI 开发,但我遇到了 PyCharm IDE 社区版 4.5.2
的问题
我的问题是:当我在 IDLE 中编写下面的代码时,它工作正常!!!
但是当我使用 PyCharm IDE 编写它时,会出现此错误消息:
AttributeError: 'module' 对象没有属性 'Tk'
请帮助我,我真的需要帮助,非常感谢
我的代码:
import Tkinter
app = Tkinter.Tk()
app.title("hello world")
app.minsize(300, 300)
helloLabel = Tkinter.Label(app, text="hello GUI")
helloLabel.pack()
app.mainloop()
注意:我正在使用 Python 2.7.6,OS:Ubuntu 14.04 LTS
问题是您将文件命名为 Tkinter.py
。当您执行导入时,python 会看到文件并尝试导入它而不是 Tkinter 库。
重命名您的文件,并确保删除 Tkinter.pyc
(如果存在)。
我开始使用 Tkinter python 库学习 GUI 开发,但我遇到了 PyCharm IDE 社区版 4.5.2
的问题我的问题是:当我在 IDLE 中编写下面的代码时,它工作正常!!! 但是当我使用 PyCharm IDE 编写它时,会出现此错误消息: AttributeError: 'module' 对象没有属性 'Tk' 请帮助我,我真的需要帮助,非常感谢
我的代码:
import Tkinter
app = Tkinter.Tk()
app.title("hello world")
app.minsize(300, 300)
helloLabel = Tkinter.Label(app, text="hello GUI")
helloLabel.pack()
app.mainloop()
注意:我正在使用 Python 2.7.6,OS:Ubuntu 14.04 LTS
问题是您将文件命名为 Tkinter.py
。当您执行导入时,python 会看到文件并尝试导入它而不是 Tkinter 库。
重命名您的文件,并确保删除 Tkinter.pyc
(如果存在)。