Tkinter CheckButton variables

Discussion in 'Python' started by Elaine Jackson, Jul 1, 2004.

  1. My CheckButton variables seem always to be true, whether the box is checked or
    not, which makes them considerably less useful. Following is a little script
    that illustrates the difficulty. Any help will be greatly appreciated. Thank
    you.

    ###########################################

    from Tkinter import *

    def bCommand():
    if c['variable']: ## ALSO TRIED: if cVbl
    print 'bool(cVbl)==True'
    else:
    print 'bool(cVbl)==False'

    root = Tk()
    cVbl = IntVar()
    c = Checkbutton(root,variable=cVbl)
    c.pack(side=LEFT)
    b = Button(root,height=1,width=10,command=bCommand)
    b.pack(side=LEFT)
    root.mainloop()
     
    Elaine Jackson, Jul 1, 2004
    #1
    1. Advertising

  2. Elaine Jackson

    klappnase Guest

    "Elaine Jackson" <> wrote in message news:<OSMEc.954254$oR5.38158@pd7tw3no>...
    > My CheckButton variables seem always to be true, whether the box is checked or
    > not, which makes them considerably less useful. Following is a little script
    > that illustrates the difficulty. Any help will be greatly appreciated. Thank
    > you.
    >
    > ###########################################
    >
    > from Tkinter import *
    >
    > def bCommand():
    > if c['variable']: ## ALSO TRIED: if cVbl
    > print 'bool(cVbl)==True'
    > else:
    > print 'bool(cVbl)==False'
    >
    > root = Tk()
    > cVbl = IntVar()
    > c = Checkbutton(root,variable=cVbl)
    > c.pack(side=LEFT)
    > b = Button(root,height=1,width=10,command=bCommand)
    > b.pack(side=LEFT)
    > root.mainloop()


    c[variable'] returns (of course) cVb1 and therefore will always be true.
    You should use

    if cVb1.get():
    (etc.)

    Michael
     
    klappnase, Jul 1, 2004
    #2
    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. Paul Rubin
    Replies:
    3
    Views:
    748
    Eric Brunel
    Jul 4, 2005
  2. Tuvas

    Tkinter- checkbutton

    Tuvas, Nov 4, 2005, in forum: Python
    Replies:
    3
    Views:
    1,102
    Tuvas
    Nov 4, 2005
  3. O.R.Senthil Kumaran
    Replies:
    3
    Views:
    967
    Eric Brunel
    Jul 5, 2007
  4. Replies:
    0
    Views:
    342
  5. Dodo
    Replies:
    6
    Views:
    1,081
Loading...

Share This Page