The code create 2 windows. 2 radiobuttons are put on the second
window. A control variable "v" is binded to the 2 widgets.
But when I run the code, I found the control variable not binded
succsessfully: The second radiobutton was not selected by default;
Click ed each button always print 1. I don't know what is wrong. So I
need help.Thanks.
from Tkinter import *
def test(event_inst ance):
print v.get()
window1=Tk()
window2=Tk()
v=IntVar()
v.set(1)
radiobutton1=Ra diobutton(windo w2,variable=v,v alue=0)
radiobutton2=Ra diobutton(windo w2,variable=v,v alue=1)
radiobutton1.pa ck()
radiobutton2.pa ck()
radiobutton2.bi nd('<Button-1>',test)
radiobutton1.bi nd('<Button-1>',test)
window1.mainloo p()
window. A control variable "v" is binded to the 2 widgets.
But when I run the code, I found the control variable not binded
succsessfully: The second radiobutton was not selected by default;
Click ed each button always print 1. I don't know what is wrong. So I
need help.Thanks.
from Tkinter import *
def test(event_inst ance):
print v.get()
window1=Tk()
window2=Tk()
v=IntVar()
v.set(1)
radiobutton1=Ra diobutton(windo w2,variable=v,v alue=0)
radiobutton2=Ra diobutton(windo w2,variable=v,v alue=1)
radiobutton1.pa ck()
radiobutton2.pa ck()
radiobutton2.bi nd('<Button-1>',test)
radiobutton1.bi nd('<Button-1>',test)
window1.mainloo p()
Comment