Python Forum
[Tkinter] Radiobutton in Tkinter not Updating Variable from Value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Radiobutton in Tkinter not Updating Variable from Value
#1
Hello. So I am trying to create a radiobutton that changes the value of another variable when clicked on. Obviously I'm missing something, because no values are changing. Here's the code:

from tkinter import *

root = Tk()

iv1 = IntVar()
iv1.set(1)
var = IntVar()
var.set(0)
rb1 = Radiobutton(master=root, value=iv1, variable=var)
rb1.pack()

num = var.get()

print(var.get())

root.mainloop()

print(num)
In my project, I will want to have four radiobuttons instead of one, but this is just a simple code that shows you the error I'm having. At the end, print(num) should give 1, but instead it equals 0. Any idea why? Thanks in advance.

EDIT:

Here is my output:

0
0
Reply
#2
use textvariable, not variable
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pass a variable between tkinter and toplevel windows janeik 10 2,321 Jan-24-2024, 06:44 AM
Last Post: Liliana
  [Tkinter] Updating tkinter text BliepMonster 5 5,945 Nov-28-2022, 01:42 AM
Last Post: deanhystad
  [Tkinter] Updating Tkinter label using multiprocessing Agusms 6 3,127 Aug-15-2022, 07:10 PM
Last Post: menator01
  [Tkinter] Update variable using tkinter entry methon drSlump 6 5,183 Oct-15-2021, 08:01 AM
Last Post: drSlump
  Updating button text based upon different variable values knoxvilles_joker 0 2,231 Apr-18-2021, 04:13 AM
Last Post: knoxvilles_joker
  [Tkinter] tkinter.Menu – How to make text-variable? Sir 3 5,620 Mar-10-2021, 04:21 PM
Last Post: Sir
  How to dynamically change radiobutton text kenwatts275 2 3,326 Mar-05-2021, 02:25 AM
Last Post: deanhystad
  Python3 tkinter radiobutton problem Nick_tkinter 14 5,988 Feb-15-2021, 11:01 PM
Last Post: Nick_tkinter
  [Tkinter] tkinter global variable chalao_adda 6 11,019 Nov-14-2020, 05:37 AM
Last Post: chalao_adda
  [Tkinter] RadioButton Maryan 2 2,162 Oct-23-2020, 09:36 PM
Last Post: Maryan

Forum Jump:

User Panel Messages

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