Skip to content

Instantly share code, notes, and snippets.

@siwells
Created October 10, 2011 15:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save siwells/1275637 to your computer and use it in GitHub Desktop.
Save siwells/1275637 to your computer and use it in GitHub Desktop.
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

from Tkinter import *

doesn't work

from tkinter import *

you need to use this instead

@peyman-bagheri
Copy link

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