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')


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'
  • I navigated to the folder the file is located in. I type python 3 scriptname.py. I also tried the ./. No cigar. Aug 19, 2018 at 23:16
  • It looks like you executed your python3 with python2 by typing python 3 scriptname.py. Instead remove the space between python and 3: python3 scriptname.py. Otherwise see this answer stackoverflow.com/questions/514371/…
    – Kev Inski
    Aug 20, 2018 at 5:16

2 Answers 2


Thanks 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.


That's actually strange. The import statement works fine (or at least doesn't raise an exception), but instead Tk() is not found. The only thing I can come up with is trying to run

import tkinter

window = tkinter.Tk()

window.title('Welcome to LikeGeeks app')


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.