Question

I was trying to start my new project with Tkinter in Python 3.3.1. So I installed ActiveTcl 8.5.13, as that seems to be required.

Now I run this simple test script;

import sys
from tkinter import *

mGui = Tk() # Instantiate the Tkinter object

Yet, the Tk() instance can't be found;

iMac2011:Desktop allendar$ python3 tkinter.py
Traceback (most recent call last):
  File "tkinter.py", line 4, in <module>
    from tkinter import *
  File "/Users/allendar/Desktop/tkinter.py", line 8, in <module>
    mGui = Tk() # Instantiate the Tkinter object
NameError: name 'Tk' is not defined

I can't seem to find info on the internet about this issue. It works without any issues on my Ubuntu distro. Is this some kind of issue with OS X needing some particular way of calling the library?

Était-ce utile?

La solution

Your problem is the name of the file is tkinter.py So when import tkinter it imports the file itself instead of the actual tkinter module. I ran into this problem myself once, it took me a while to figure it out. Change the name of the file and it should fix your problem.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top