Skip to content

Instantly share code, notes, and snippets.

@infamousjoeg
Created September 17, 2018 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infamousjoeg/e6ff8e9e8704ba1b27bfe3ee68a40ec7 to your computer and use it in GitHub Desktop.
Save infamousjoeg/e6ff8e9e8704ba1b27bfe3ee68a40ec7 to your computer and use it in GitHub Desktop.
Reference Cheat Sheet for Tkinder module GUI in Python 2.7
from Tkinter import *
def clickme_clicked():
response = "Welcome to " + txt.get()
lbl.configure(text = response)
print(rad_selected.get())
messagebox.showinfo('Script Status','Completed!')
# Start the window
window = Tk()
# Set parameters for the window
window.title("Hello World")
window.geometry("400x500")
# Label Example
lbl = Label(window, text="Hello World!")
lbl.grid(column=0, row=0)
# Button Example
btn = Button(window, text="Click Me", command=clickme_clicked)
btn.grid(column=0, row=1)
# Input Example
txt = Entry(window, width=10) # , state='disabled'
txt.grid(column=1, row=0)
txt.focus()
# Checkbox Example
chk_state = BooleanVar()
chk_state.set(False)
chk = Checkbutton(window, text='Choose', var=chk_state)
chk.grid(column=2, row=0)
# Radio Buttons Example
rad_selected = IntVar()
rad1 = Radiobutton(window, text='First', value=1, variable=rad_selected)
rad2 = Radiobutton(window, text='Second', value=2, variable=rad_selected)
rad3 = Radiobutton(window, text='Third', value=3, variable=rad_selected)
rad1.grid(column=0, row=2)
rad2.grid(column=1, row=2)
rad3.grid(column=2, row=2)
# Show the window
# But first, set its attributes to show it on top
# to start
window.call('wm', 'attributes', '.', '-topmost', '1')
window.mainloop()
@infamousjoeg
Copy link
Author

image

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