IcyFlame
IcyFlame

Reputation: 5209

Radio button in a Tkinter menu

goal

Understanding how a radiobutton in a Tkinter menu works

code

I have a radio button inside the options menu as so:

v = BooleanVar()

v.set(True)

options.add_radiobutton(label="change pop up", command =togglePopUp,variable=v,onvalue=True,offvalue=False)

togglePopUp is a function that changes the value of variable v from True to False or vice versa. Main window is already opened and this menu will be added later to the window. This is just the fragment of code that is related to the radiobutton.

Question

Now my question is when I press the radiobutton (after running the code) will the value of the variable be changed or will the function togglePopUp be called? If the function will be called then what will happen to the status of the radiobutton? will the status of the radiobutton be updated instantly or will there be a delay?

research

I read about the radiobutton and the Boolean variable from the Tkinter book at effbot.org. But I was not convinced about how it worked. I tried a program but I am not getting the output that I essentially want. So I decided to understand how it works at a deeper level.

specs python 2.7 Tkinter 8.5 Linux Mint 14

Upvotes: 3

Views: 5070

Answers (1)

A. Rodas
A. Rodas

Reputation: 20689

Both actions will occur. When you click on a radiobutton, first the variable will change its value, and after that the event handler passed as command option is called if present.

Also your example would not work, since add_radiobutton doesn't allow the onvalue and offvalue options - only value.

Upvotes: 3

Related Questions