Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Python GUI "Hello World" using Tkinter
from Tkinter import *
root = Tk()
w = Label(root, text="Hello World")
w.pack()
root.mainloop()
@peroh215
Copy link

peroh215 commented Oct 12, 2018

from Tkinter import *

doesn't work

from tkinter import *

you need to use this instead

@peyman-bagheri
Copy link

peyman-bagheri commented Jul 11, 2019

why Tk not defined

@siwells
Copy link
Author

siwells commented Jul 11, 2019

For the import It's a Python 2 versus 3 thing. Looks like the package might have been renamed. Obviously if the import fails then Tk() (or tk()) won't be available as a result.

@bentaye
Copy link

bentaye commented Oct 3, 2019

That module name has changed from Tkinter in Python 2 to tkinter in Python 3

@sarkiroka
Copy link

sarkiroka commented Dec 15, 2019

sudo apt-get install python3-tk Installs tkinter for Python3.x.x

hello-world.py:

from tkinter import *
root = Tk()
myLabel = Label(root, text = 'Hello, sarkiroka!')
myLabel.pack()
root.mainloop()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment