AttributeError:'module'对象没有属性'Tk'

Ham*_*ira 2 python tkinter pycharm python-2.7

我开始使用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()
Run Code Online (Sandbox Code Playgroud)

注意:我使用的是Python 2.7.6,操作系统:Ubuntu 14.04 LTS

Bry*_*ley 11

问题是你命名了你的文件Tkinter.py.当您执行导入时,python会看到该文件并尝试导入它而不是Tkinter库.

重命名您的文件,并确保删除Tkinter.pyc它是否存在.