By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 1,989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

CheckButton -- modify "check state"

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.