-
-
Save memilanuk/7d88bd9d6c41d9a77698 to your computer and use it in GitHub Desktop.
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
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() |
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
Cleaned up to where it at least works, if not fully functional yet. Using PyCharm 4; should be 'clean' in terms of PEP8, etc.
Using Python3 syntax; change the import line accordingly for py2x/Tkinter.