CheckButton -- modify "check state"

A

Askari

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
 
I

Irmen de Jong

Askari said:
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
 
E

Eric Brunel

Askari said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,944
Members
47,492
Latest member
gabbywilliam

Latest Threads

Top