469,342 Members | 6,184 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

CheckButton -- modify "check state"

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
Jul 18 '05 #1
2 2948
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
Jul 18 '05 #2
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

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by C P | last post: by
4 posts views Thread by Hrishi R | last post: by
4 posts views Thread by louvino | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by haryvincent176 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.