When the application changes its theme everything changes except the
menus.
What is the recomended way to change the menubar and all its entries,
I cannot sem to find a way of listing the menus available.
Martyn
Menus aren't styled at all because Ttk doesn't supply them. (On Win
and OSX, they're just straight native.) However, what you could do is
to ask what the background of a [ttk::frame] is:
ttk::style lookup TFrame -background
And then configure the menu to use that as the background. That should
give a reasonable approximation to what menus ought to be. (Remember
to watch for the <<ThemeChanged>> virtual event so that you know when
to look up the background and reapply it again.)
Donal.
>[snip]
>I cannot sem to find a way of listing the menus available.
>
>Martyn
>
>
Well I assume you're running into the cloning functionallity in Tk.
menu .menubar
menu .xyz.menubar
is cloned as
.#menubar
.xyz.#xyz#menubar
The clone is what you see in your application.
The best way to deal with menus is to generate them
just before they are posted (aka postcommand), this
also allows it to utilize commands as checkbuttons
--as recommended
in the AQUA Human Computer Interface Guidelines.
Take a look at gstripes (X11 Only):
http://gestaltitems.sourceforge.net/geitems/Gstripes_Menus.html
.. the same mechanism could be used with ttk under X11, too.
-roger
I already have code connected to the <<ThemeChanged>> virtual event
(to change a couple of canvas backgrounds and a Bwidget notebook) what
I need is a list of the menus for each window (preferably without
changing all the menu creation code to record the menu id's).
Is there no introspection command to give me a list of menus in the
menu bar and for each menu a list of indexes to configure.
Martyn
set last [$menu index end]
for {set index 0} {$index <= $last} {incr index} {
if {[catch {$menu entrycget $index -label} label]} {
set label "(separator)"
}
puts [list $index $label]
}
will list the labels for all menu entries in $menu.
--
Pat Thoyts http://www.patthoyts.tk/
To reply, rot13 the return address or read the X-Address header.
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
bind Menu <<ThemeChanged>> {ChangeMenuColors %W}
Schelte.
Yes, there is plenty of introspection. For example, [. cget -menu]
will give you the menu associated with the main window. Given a menu
you can use the index command like [$menu index end] to get the index
of the last item. You can then loop from zero to that number, and use
entrycget to get the value for each item. And so on.
If you need to know what popup menus exist (ie: those not tied to a
toplevel with the -menu option) you can get a list of all widgets (I'm
usually lazy and do [info commands .*]) and pick out the ones you want
by looking at the widget class. In the case of menus you need to
exclude clones.
set nEntries [$menu index end]
for {set i 1} {$i <= $nEntries} {incr i} {
puts stdout [join [$menu entryconfigure $i] \n]
}
For a cascade, there will be another menu widget entryconfigured as
-menu and you can do the same thing to that menu.
I seem to recall being confused by some of the things I found when I
first did this kind of thing but a quick test just now held no surprises.
Hope this helps!
Alan
Thanks for all your replies, especially Schelte who shows the KISS
rule of TCL.
Everything is now working correctly.
Martyn