Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TTK and menubars

662 views
Skip to first unread message

MSEdit

unread,
Nov 27, 2009, 11:23:38 AM11/27/09
to

I have several applications which use menubars and ttk.

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

Donal K. Fellows

unread,
Nov 28, 2009, 3:24:08 AM11/28/09
to

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.

Arndt Roger Schneider

unread,
Nov 28, 2009, 6:03:03 AM11/28/09
to
MSEdit schrieb:

>[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

MSEdit

unread,
Nov 30, 2009, 11:07:46 AM11/30/09
to

My problem is not to configure or find the colours but to be able to
loop over the menubar elements.

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

MSEdit

unread,
Nov 30, 2009, 11:07:46 AM11/30/09
to

Pat Thoyts

unread,
Nov 30, 2009, 2:01:42 PM11/30/09
to
MSEdit <mse...@gmail.com> writes:

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

Schelte Bron

unread,
Nov 30, 2009, 2:06:33 PM11/30/09
to
MSEdit wrote:
> 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).
>
You are working too hard. Just add the virtual event to the widget
class and it will automatically be called for each menu widget:

bind Menu <<ThemeChanged>> {ChangeMenuColors %W}


Schelte.

Bryan Oakley

unread,
Nov 30, 2009, 2:14:22 PM11/30/09
to

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.

Alan Grunwald

unread,
Nov 30, 2009, 2:16:15 PM11/30/09
to
Have you looked at

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

MSEdit

unread,
Dec 1, 2009, 4:48:02 AM12/1/09
to

Thanks for all your replies, especially Schelte who shows the KISS
rule of TCL.

Everything is now working correctly.

Martyn

0 new messages