Tkinter CheckButton variables

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

    Tkinter CheckButton variables

    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)==Tr ue'
    else:
    print 'bool(cVbl)==Fa lse'

    root = Tk()
    cVbl = IntVar()
    c = Checkbutton(roo t,variable=cVbl )
    c.pack(side=LEF T)
    b = Button(root,hei ght=1,width=10, command=bComman d)
    b.pack(side=LEF T)
    root.mainloop()


  • klappnase

    #2
    Re: Tkinter CheckButton variables

    "Elaine Jackson" <elainejackson7 355@home.com> wrote in message news:<OSMEc.954 254$oR5.38158@p d7tw3no>...[color=blue]
    > 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)==Tr ue'
    > else:
    > print 'bool(cVbl)==Fa lse'
    >
    > root = Tk()
    > cVbl = IntVar()
    > c = Checkbutton(roo t,variable=cVbl )
    > c.pack(side=LEF T)
    > b = Button(root,hei ght=1,width=10, command=bComman d)
    > b.pack(side=LEF T)
    > root.mainloop()[/color]

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

    if cVb1.get():
    (etc.)

    Michael

    Comment

    Working...