Reputation: 1
I'm trying to learn how to use tkinter to create a GUI with python. I just installed Visual Studio Code as I wanted to try a new IDE, but I get the following error when trying to run my code:
AttributeError: module 'tkinter' has no attribute 'Tk'
The code in question is just:
import tkinter as tk
tk.Tk()
I have tried to run the same code in IDLE and PyCharm, where it works fine. I can also without problems write the same code in the python shell from within VSC. I have tried to import other modules into VSC and that code runs just fine when I call the modules. Any suggestions?
Upvotes: 0
Views: 290
Reputation: 3957
You probably have some tkinter.py
file created in the current directory and because of the higher precedence that module/file is imported when you call import tkinter as tk
.
Just rename that tkinter.py
file to something else.
Upvotes: 2