python - 属性错误 : 'module' object has no attribute 'Tk'

标签 python python-2.7 tkinter pycharm

我开始使用 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,操作系统:Ubuntu 14.04 LTS

最佳答案

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

重命名您的文件,并确保删除 Tkinter.pyc(如果存在)。

关于python - 属性错误 : 'module' object has no attribute 'Tk' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31303719/

相关文章:

python - 在 Django Rest Framework 中列出具有动态字段的序列化程序

string - 为什么我无法通过使用 psycopg2 使用 cursor.execute 查询字符串来获得响应?

image - Tkinter Canvas不会在c.create_image上显示图像

django - 为什么 Debug模式下的 app/admin false 给我服务器错误 500

python - Tkinter 'module' 对象不可调用

python - 类型错误: '>' 和 'function' 实例之间不支持 'int'

python - 将非连续值分组到列表中

python - 如何自动创建变量?

python - 我如何根据值的范围对数据进行分组

python - 使用带有 Initializer 的对象方法(同一行)