Nov-24-2021, 10:36 AM
#! /usr/bin/env python3.10 import tkinter as tk root = tk.Tk() def show(): print(f' Variable AB -> {var_ab.get()}') print(f' Variable CD -> {var_cd.get()}') var_ab = tk.IntVar() var_cd = tk.IntVar() tk.Label(root, text="""Radio Buttons""", justify = tk.LEFT).grid (row = 1, column = 1) tk.Radiobutton(root, text="A", padx = 20, variable=var_ab, command=show, value=1).grid (row = 2, column = 1) tk.Radiobutton(root, text="B", padx = 20, variable=var_ab, command=show, value=2).grid (row = 2, column = 2) tk.Radiobutton(root, text="C", padx = 20, variable=var_cd, command=show, value=3).grid (row = 3, column = 1) tk.Radiobutton(root, text="D", padx = 20, variable=var_cd, command=show, value=4).grid (row = 3, column = 2) root.mainloop()
Output: Variable AB -> 1
Variable CD -> 0
Variable AB -> 1
Variable CD -> 4
Variable AB -> 1
Variable CD -> 3
Variable AB -> 2
Variable CD -> 3
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags