Tkinter Radio button on the second window

Dream god1124 at gmail.com
Thu Sep 4 21:01:25 EDT 2008


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_instance):
	print v.get()

window1=Tk()
window2=Tk()
v=IntVar()
v.set(1)
radiobutton1=Radiobutton(window2,variable=v,value=0)
radiobutton2=Radiobutton(window2,variable=v,value=1)
radiobutton1.pack()
radiobutton2.pack()
radiobutton2.bind('<Button-1>',test)
radiobutton1.bind('<Button-1>',test)
window1.mainloop()




More information about the Python-list mailing list