CheckButton -- modify "check state"

Discussion in 'Python' started by Askari, Jan 14, 2004.

  1. Askari

    Askari Guest

    Hi,
    How do for do a "select()" on a CheckButton in a menu (make with
    add_checkbutton(....) )?
    I can modify title, state, etc but not the "check state". :-(

    Askari
    Askari, Jan 14, 2004
    #1
    1. Advertising

  2. Askari wrote:

    > How do for do a "select()" on a CheckButton in a menu (make with
    > add_checkbutton(....) )?
    > I can modify title, state, etc but not the "check state". :-(


    I have no clue what you're talking about: you have to at least
    tell us what GUI toolkit you're using, and preferrably, show
    a snippet of code.

    --Irmen
    Irmen de Jong, Jan 14, 2004
    #2
    1. Advertising

  3. Askari

    Eric Brunel Guest

    Askari wrote:
    > Hi,
    > How do for do a "select()" on a CheckButton in a menu (make with
    > add_checkbutton(....) )?
    > I can modify title, state, etc but not the "check state". :-(


    Assuming you're using Tkinter, the way to do it is to use the variable option
    when you create the menu, and them modify the variable. Here is an example code:

    --menu.py------------------------
    from Tkinter import *

    root = Tk()

    ## Create the menu bar
    menuBar = Menu(root)
    root.configure(menu=menuBar)

    ## Create the menu
    menu = Menu(menuBar)
    menuBar.add_cascade(label='Menu', menu=menu)

    ## Create the variable for the check button
    myCheckVar = BooleanVar()

    ## Functions to check/uncheck/print the check state
    def check(*whatever): myCheckVar.set(1)
    def uncheck(*whatever): myCheckVar.set(0)
    def print_option(*whatever): print myCheckVar.get()

    ## Entries in menu
    menu.add_checkbutton(label='Option', variable=myCheckVar)
    menu.add_command(label='Check', command=check)
    menu.add_command(label='Uncheck', command=uncheck)
    menu.add_command(label='Print', command=print_option)

    root.mainloop()
    ---------------------------------

    If you do not specify a command for the add_checkbutton, the default action is
    to toggle the check state.

    HTH
    --
    - Eric Brunel <eric dot brunel at pragmadev dot com> -
    PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
    Eric Brunel, Jan 15, 2004
    #3
    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:
    430
    klappnase
    Jul 1, 2004
  2. Paul Rubin
    Replies:
    3
    Views:
    739
    Eric Brunel
    Jul 4, 2005
  3. Tuvas

    Tkinter- checkbutton

    Tuvas, Nov 4, 2005, in forum: Python
    Replies:
    3
    Views:
    1,095
    Tuvas
    Nov 4, 2005
  4. Thomas Jansson
    Replies:
    3
    Views:
    244
    Thomas Jansson
    May 14, 2007
  5. O.R.Senthil Kumaran
    Replies:
    3
    Views:
    959
    Eric Brunel
    Jul 5, 2007
Loading...

Share This Page