Skip to content

Instantly share code, notes, and snippets.

@memilanuk
Forked from anonymous/reddit.py
Last active August 29, 2015 14:10
Show Gist options
  • Save memilanuk/7d88bd9d6c41d9a77698 to your computer and use it in GitHub Desktop.
Save memilanuk/7d88bd9d6c41d9a77698 to your computer and use it in GitHub Desktop.
import tkinter as tk
root = tk.Tk()
root.wm_title('Radio Buttons')
label1 = tk.Label(root)
label1.config(text='Please select an option below.')
label1.pack()
def update_label2(option, value):
selection = "current selection is: \n\n" + str(option) + ": " + str(value)
label2.config(text=selection)
var = tk.IntVar()
var.set(100)
R1 = tk.Radiobutton(root, text='A', value=100, variable=var,
command=lambda: update_label2('A', 100))
R1.pack(anchor='center')
R2 = tk.Radiobutton(root, text='B', value=80, variable=var,
command=lambda: update_label2('B', 80))
R2.pack(anchor='center')
R3 = tk.Radiobutton(root, text='C', value=60, variable=var,
command=lambda: update_label2('C', 60))
R3.pack(anchor='center')
label2 = tk.Label(root)
label2.config(text='Current selection is: \n \nA: 100')
label2.pack()
root.mainloop()
@memilanuk
Copy link
Author

Edited to utilize lambda for the callbacks from the radio buttons to the function that sets the label text.

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