[英]Python: It does not let me use Tkinter root = Tk() error
I am quite new to Python, but know the basics. 我对Python相当陌生,但了解一些基础知识。 I have been watching a few tutorials about
Tkinter
, but even from the start when I type: 我一直在看一些有关
Tkinter
教程,但是即使从一开始我就输入:
from Tkinter import *
root = Tk()
It gives me the error: 它给了我错误:
>Traceback (most recent call last):
File "/Users/$Name/Desktop/PycharmProjects/untitled/Tkinter.py", line 1, in <module>
from Tkinter import *
File "/Users/$Name/Desktop/PycharmProjects/untitled/Tkinter.py", line 3, in <module>
root = Tk()
NameError: name 'Tk' is not defined
I've tried different things, and I have used IDLE
, and it still does not work. 我尝试了不同的方法,并且使用了
IDLE
,但仍然无法正常工作。 I am also on Mac OS X El Capitan if that should matter. 如果应该的话,我也在Mac OS X El Capitan上。
You named your file Tkinter.py
. 您将文件命名为
Tkinter.py
。 So you are importing your own file. 因此,您正在导入自己的文件。 Rename your python file, delete
Tkinter.pyc
and try again. 重命名您的python文件,删除
Tkinter.pyc
然后重试。
I tried this and it worked 我尝试了这个并且有效
import tkinter as tk
root = tk.Tk()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.