Ttk's menubutton widget.
jnc To invoke a menu button (or almost any other widget that takes a -text and -underline option) by a keystroke you can:
event generate $widget <<Invoke>>
Such as:
bind <Alt-f> . {event generate .menuButton <<Invoke>>}
HaO 2010-11-16 Is there any possibility to center-align the menu button text and image ? This would make the following example nicer (on Windows Vista classic theme):
("Laden" has nothing to do with the person, it is German for "Load (Module in this case)")
Labels and Images are left-aligned.
Code fragment (not that of the screenshot):
% pack [ttk::menubutton .t1 -text abcabcabc] -fill x % pack [ttk::menubutton .t2 -text a] -fill x
Style investigation:
% ttk::style layout TMenubutton Menubutton.border -sticky nswe -children {Menubutton.focus -sticky nswe -children {Menubutton.indicator -side right -sticky {} Menubutton.padding -expand 1 -sticky we -children {Menubutton.label - side left -sticky {}}}}
I think, the issue is the last part. "-side left -sticky {}" which should be changed to "-sticky news" Is this possible in an easy manner ?
--- Even harder, I want to have it with Toolbutton style:
% pack [ttk::menubutton .t1 -text abcabcabc -style Toolbutton] -fill x % pack [ttk::menubutton .t2 -text a -style Toolbutton] -fill x
How to align the labels "centered ?"
--- Style investigation:
% ttk::style layout Toolbutton Toolbutton.border -sticky nswe -children {Toolbutton.padding -sticky nswe -children {Toolbutton.label -sticky nswe}}
Here, the label has -sticky "nswe". So try some label-options:
% ttk::style configure Toolbutton.label -justify center -anchor center % pack [ttk::menubutton .t3 -text a -style Toolbutton] -fill x
But stil left-aligned...
But
% ttk::style theme use clam
and the Toolbutton styled menubuttons are center-aligned.
Why is a normal Button centered and a MenuButton left-aligned ?
If you have an answer feel free to remove all this and replace it by more helpful stuff. I have posted this on c.l.t. with no answer and solved it by putting the label to the right of the icon so it looks pretty when left-aligned.
EG: Remove the "-side left" and add "-sticky ns".
For plain ttk::menubuttons:
% ttk::style layout TMenubutton { Menubutton.border -sticky nswe -children { Menubutton.focus -sticky nswe -children { Menubutton.indicator -side right -sticky {} Menubutton.padding -expand 1 -sticky we -children { Menubutton.label -sticky ns } } } }
and for the Toolbutton styled ones:
% ttk::style layout Toolbutton { Toolbutton.border -sticky nswe -children { Toolbutton.padding -sticky nswe -children { Toolbutton.label -sticky ns } } }
HaO 2011-05-10 To post the menu also on the right mouseclick, one may generate the left events also on the right click events:
bind TMenubutton <ButtonPress-3> { event generate %W <ButtonPress-1> } bind TMenubutton <ButtonRelease-3> { event generate %W <ButtonRelease-1> }
HaO 2011-05-10 I tried to post the menu if the mouse is over the menubutton.
There is no issue to post the menu when the mouse is over by:
if {[tk windowingsystem] eq "x11"} { bind TMenubutton <Enter> { ttk::menubutton::Pulldown %W } bind TMenubutton <Leave> { ttk::menubutton::TransferGrab %W } } else { bind TMenubutton <Enter> \ { %W instate !disabled {%W state active ;\ %W state pressed ;\ ttk::menubutton::Popdown %W }} bind TMenubutton <Leave> \ { %W state !active ; %W state !pressed } }
Windows issues: The menu is well posted and gets a local grab which may only be unposted by clicking outside the menu.
With two menubuttons, the following happens: