I am quite new to Python, but know the basics. I have been watching a few tutorials about Tkinter
, but even from the start when I type:
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. I am also on Mac OS X El Capitan if that should matter.
You named your file Tkinter.py
. So you are importing your own file. Rename your python file, delete Tkinter.pyc
and try again.
I tried this and it worked
import tkinter as tk
root = tk.Tk()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.