Python Forum
[Tkinter] Grid the radio buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Grid the radio buttons
#5
Hi, yes now I able to run this code having radio buttons which are arranged in rows and cols and are linked together. The buttons A and B are linked and have their value in same variable. Same is true for buttons C and D.

Now I need to print their their values when the radio button is selected but I it is not printing the values in the code below.

import tkinter as tk
 
root = tk.Tk()
 
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, 
               value=1).grid (row = 2, column = 1)
 
tk.Radiobutton(root, 
               text="B",
               padx = 20, 
               variable=var_ab, 
               value=2).grid (row = 2, column = 2)

tk.Radiobutton(root, 
               text="C",
               padx = 20, 
               variable=var_cd, 
               value=3).grid (row = 3, column = 1)

tk.Radiobutton(root, 
               text="D",
               padx = 20, 
               variable=var_cd, 
               value=4).grid (row = 3, column = 2)

print("The Variable AB = " , var_ab)
print("The Variable CD = " , var_cd)

root.mainloop() 
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,105 Jan-31-2023, 09:44 AM
Last Post: Vadanane
  [Tkinter] Radio Buttons Working Bassackwards gw1500se 6 2,333 Dec-07-2021, 07:13 PM
Last Post: menator01
  Radio butto to enable/disable combo box in Tkinter cybertooth 5 5,564 Oct-09-2021, 07:30 AM
Last Post: cybertooth
  problem with radio button crook79 3 3,747 Aug-12-2021, 02:30 PM
Last Post: deanhystad
  .grid buttons AnunnakiKungFu 3 2,023 Feb-08-2021, 05:56 PM
Last Post: deanhystad
  [Tkinter] I can't get information from a radio button aquerci 2 2,778 May-20-2020, 10:31 AM
Last Post: aquerci
  [Tkinter] Radio button help Muzz 5 3,713 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