Created
September 17, 2018 21:39
-
-
Save infamousjoeg/e6ff8e9e8704ba1b27bfe3ee68a40ec7 to your computer and use it in GitHub Desktop.
Reference Cheat Sheet for Tkinder module GUI in Python 2.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Author
infamousjoeg
commented
Sep 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment