I'm trying to complete this tutorial https://likegeeks.com/python-gui-examples-tkinter-tutorial/amp/.
I have the following code written
from tkinter import *
window = Tk()
window.title('Welcome to LikeGeeks app')
window.mainloop()
I have run the command
sudo apt install python3-tk
However I am still getting the following error:
NameError: name 'Tk' is not defined
The Python version on my machine is Python 3.6.5.
Turtle graphics work fine.
edit: I renamed the file from tkinter.py to test.py and I got this error message
Traceback (most recent call last):
File "test.py", line 1, in <module>
from tkinter import *
ImportError: bad magic number in 'tkinter': b'\x03\xf3\r\n'
That's actually strange. The
import
statement works fine (or at least doesn't raise an exception), but insteadTk()
is not found. The only thing I can come up with is trying to runThanks to SteelDriver for figuring this out. The file should not be named tkinter.py.
It gave me a traceback and I was able to google it and a .pyc file was causing the error.