Python Forum

Full Version: Radiobutton in Tkinter not Updating Variable from Value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
use textvariable, not variable