tkinter menu bar problem
Eric Brunel
eric_brunel at despammed.com
Wed Feb 9 07:10:59 EST 2005
On Wed, 09 Feb 2005 11:35:40 GMT, John Pote <johnpote at blueyonder.co.uk>
wrote:
> I have a menu bar in a top level window as follows
[snip code]
>
> Q1 Cannot find a way of changing the menu bars background colour. When
> colour options are accepted they seem to be ignored. Is this a native
> look
> and feel characteristic of write once run anywhere, not yet implemented
> or
> possibly a bug.
Even if the tk man pages [1] don't mention it, it would not be surprising
if the background option for menu items did not work on Windows, since
many things seem to be "hardcoded" on this platform. I tested the
following code on Linux; it works without problem and has the expected
behaviour:
>>> from Tkinter import *
>>> root = Tk()
>>> mb = Menu(root)
>>> root.configure(menu=mb)
>>> m = Menu(mb)
>>> mb.add_cascade(label='Menu', menu=m)
>>> m.add_command(label='Quit', command=root.quit, background='red')
If it is what you did and if it doesn't work on Windows, it is likely that
the background option for menu items is not supported for this platform...
> Q2 Some of the menu options in the config menu will not always be
> available
> depending on program state. How can individual items in such a menu be
> turned to faint gey to indicate their unavailability. Also a tick mark
> against an item would be useful to show the currently selected option. Is
> this possible?
To "grey out" a menu item:
parentMenu.entryconfigure(itemIndex, state=DISABLED)
To have menu items with a check-mark, use the add_checkbutton or
add_radiobutton methods on the parent menu. Their use is similar to the
Checkbutton and Radiobutton classes. See [1] for all available options.
[1] http://www.tcl.tk/man/tcl8.4/TkCmd/menu.htm
- Eric Brunel -
More information about the Python-list
mailing list