Tkinter Checkbutton initialization problem

Discussion in 'Python' started by Paul Rubin, Jul 3, 2005.

  1. Paul Rubin

    Paul Rubin Guest

    Python 2.4, Windows XP. If I say:

    f = Frame()
    f.grid()
    v = IntVar()
    c = Checkbutton(f, text='hi there', variable=v)
    c.grid()
    f.mainloop()

    then the checkbutton should initially display as being checked.
    But it doesn't. It shows up unchecked, even though v.get() returns 1.
    The select operation DOES update the display if there's no variable.

    It works properly under Linux with (I think) Python 2.3. I don't have
    a 2.4.1 Windows installation to try right now.

    Is this a known bug? Is it fixed in 2.4.1? Is there a simple
    workaround, that lets me initialize a checkbutton and still be able to
    read its state?

    Thanks.
     
    Paul Rubin, Jul 3, 2005
    #1
    1. Advertising

  2. Paul Rubin wrote:
    > Python 2.4, Windows XP. If I say:
    > f = Frame()
    > f.grid()
    > v = IntVar()

    v.set(1) # Might help. v.get() at this point returned 0 for me.
    > c = Checkbutton(f, text='hi there', variable=v)
    > c.grid()
    > f.mainloop()
     
    Scott David Daniels, Jul 3, 2005
    #2
    1. Advertising

  3. Paul Rubin

    Paul Rubin Guest

    Scott David Daniels <> writes:

    > Paul Rubin wrote:
    > > Python 2.4, Windows XP. If I say:
    > > f = Frame()
    > > f.grid()
    > > v = IntVar()

    > v.set(1) # Might help. v.get() at this point returned 0 for me.


    Yeah, I tried that too. Further reorganization of the code in some
    other way suddenly made it start working. I'll have to examine it to
    see what I did since I wasn't paying attention to that particular
    problem at the time. I had checked sf.net for a bug report on this
    and didn't see one, but maybe didn't check carefully enough. I'll
    look a little more and then file one, I guess.
     
    Paul Rubin, Jul 3, 2005
    #3
  4. Paul Rubin

    Eric Brunel Guest

    On 03 Jul 2005 02:32:21 -0700, Paul Rubin <http://> wrote:

    > Python 2.4, Windows XP. If I say:
    >
    > f = Frame()
    > f.grid()
    > v = IntVar()
    > c = Checkbutton(f, text='hi there', variable=v)
    > c.grid()
    > f.mainloop()
    >
    > then the checkbutton should initially display as being checked.
    > But it doesn't. It shows up unchecked, even though v.get() returns 1.
    > The select operation DOES update the display if there's no variable.


    In tcl/tk, booleans are not integers. So using an IntVar to represent something which is basically a boolean will cause unexpected behaviors like the one you're experiencing here. Just do:

    ....
    v = BooleanVar()
    v.set(1)
    ....

    and everything should be fine.

    HTH
    --
    python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
     
    Eric Brunel, Jul 4, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elaine Jackson

    Tkinter CheckButton variables

    Elaine Jackson, Jul 1, 2004, in forum: Python
    Replies:
    1
    Views:
    435
    klappnase
    Jul 1, 2004
  2. Tuvas

    Tkinter- checkbutton

    Tuvas, Nov 4, 2005, in forum: Python
    Replies:
    3
    Views:
    1,107
    Tuvas
    Nov 4, 2005
  3. O.R.Senthil Kumaran
    Replies:
    3
    Views:
    976
    Eric Brunel
    Jul 5, 2007
  4. Replies:
    0
    Views:
    347
  5. Dodo
    Replies:
    6
    Views:
    1,085
Loading...

Share This Page