Tkinter Radio button on the second window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dream

    Tkinter Radio button on the second window

    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()

  • Gabriel Genellina

    #2
    Re: Tkinter Radio button on the second window

    En Thu, 04 Sep 2008 22:01:25 -0300, Dream <god1124@gmail. comescribi�:
    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 *
    window1=Tk()
    window2=Tk()
    Don't create more than one root Tk instance. Weird things happen, like
    this.
    If you need another, separate window, use a Toplevel widget.

    --
    Gabriel Genellina

    Comment

    • Guilherme Polo

      #3
      Re: Tkinter Radio button on the second window

      On Thu, Sep 4, 2008 at 10:01 PM, Dream <god1124@gmail. comwrote:
      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()
      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=Ra diobutton(windo w2,variable=v,v alue=0)
      radiobutton2=Ra diobutton(windo w2,variable=v,v alue=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.pa ck()
      radiobutton2.pa ck()
      radiobutton2.bi nd('<Button-1>',test)
      radiobutton1.bi nd('<Button-1>',test)
      window1.mainloo p()
      >
      --

      >


      --
      -- Guilherme H. Polo Goncalves

      Comment

      • Dream

        #4
        Re: Tkinter Radio button on the second window

        Thank you very much.

        Now I use "window2=Toplev el()" to create the second window, and it
        works well.

        Comment

        Working...