Skip to content

Instantly share code, notes, and snippets.

@kitten77
Last active January 10, 2018 10:37
Show Gist options
  • Save kitten77/9af523977a739f4ebbf7eef9b328ee2c to your computer and use it in GitHub Desktop.
Save kitten77/9af523977a739f4ebbf7eef9b328ee2c to your computer and use it in GitHub Desktop.
simple hello world tkinter
import sys
from tkinter import *
"""
A simple hello world written in python and tkinter
"""
#setup size for the root window
width = 200
height = 100
root = Tk() #Creates a root window
label1 = Label(root) #creates the first label
label1.config(text='Hello world!') #configure the label
label1.pack(side=TOP, expand=YES, fill=BOTH) #packs this into the root window
button1 = Button(None, text="press me to exit", command=sys.exit) #creates your first button with a sys.exit command to exit the GUI
button1.pack(side=LEFT, expand=YES, fill=X) #packs this into the root window
root.title('hello world') #titles the root window
root.geometry('{}x{}'.format(width, height)) #resize the window so that it isnt just a tiny blob
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment