On Thu, Sep 4, 2008 at 10:01 PM, Dream <[EMAIL PROTECTED]> wrote: > 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()
Now you have created two Tcl interpreters, and Tkinter stores the "default master" as the first one created, so window1 is the default master. > v=IntVar() Here is your variable with no master specified, meaning it will use the default master, "window1". > v.set(1) > radiobutton1=Radiobutton(window2,variable=v,value=0) > radiobutton2=Radiobutton(window2,variable=v,value=1) Now you set the master for your buttons as window2, and use a variable that has as master window1. This is the big problem, besides the use of two Tcl interpreters. Tkinter doesn't really try to make this situation work, so you better not continue with it. > radiobutton1.pack() > radiobutton2.pack() > radiobutton2.bind('<Button-1>',test) > radiobutton1.bind('<Button-1>',test) > window1.mainloop() > > -- > http://mail.python.org/mailman/listinfo/python-list > -- -- Guilherme H. Polo Goncalves -- http://mail.python.org/mailman/listinfo/python-list