Andreas
Andreas

Reputation: 13

Python: It does not let me use Tkinter root = Tk() error

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.

Upvotes: 0

Views: 4576

Answers (2)

mohamed islam
mohamed islam

Reputation: 1

I tried this and it worked

import tkinter as tk    
root = tk.Tk()

Upvotes: 0

Daniel
Daniel

Reputation: 42758

You named your file Tkinter.py. So you are importing your own file. Rename your python file, delete Tkinter.pyc and try again.

Upvotes: 5

Related Questions