Python Forum
[Tkinter] Grid the radio buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Grid the radio buttons
#6
#! /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


Reply


Messages In This Thread
Grid the radio buttons - by Joni_Engr - Nov-23-2021, 03:33 PM
RE: Grid the radio buttons - by DPaul - Nov-23-2021, 04:18 PM
RE: Grid the radio buttons - by BashBedlam - Nov-23-2021, 04:18 PM
RE: Grid the radio buttons - by deanhystad - Nov-23-2021, 04:26 PM
RE: Grid the radio buttons - by Joni_Engr - Nov-24-2021, 09:54 AM
RE: Grid the radio buttons - by menator01 - Nov-24-2021, 10:36 AM
RE: Grid the radio buttons - by menator01 - Nov-24-2021, 07:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Is there a way to determine if a radio button has been selected? TWB 5 5,115 Jan-31-2023, 09:44 AM
Last Post: Vadanane
  [Tkinter] Radio Buttons Working Bassackwards gw1500se 6 2,334 Dec-07-2021, 07:13 PM
Last Post: menator01
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,570 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  problem with radio button crook79 3 3,752 Aug-12-2021, 02:30 PM
Last Post: deanhystad
  .grid buttons AnunnakiKungFu 3 2,024 Feb-08-2021, 05:56 PM
Last Post: deanhystad
  [Tkinter] I can't get information from a radio button aquerci 2 2,781 May-20-2020, 10:31 AM
Last Post: aquerci
  [Tkinter] Radio button help Muzz 5 3,714 Apr-28-2019, 07:43 AM
Last Post: Muzz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020