The problem is that they do not change when ttk::setTheme is used.
There is no ttk::menu, so what is the official way to have themed
menus which change if the theme is changed.
I have tried doing a
bind Menu <<ThemeChanged>> {ChangeMenuColors %W}
but have problems consistently recovering the current theme colours
for all states.
Martyn
What OS are you on?
The reason I ask is that menus are done by the native window system on
Microsoft Windows and Mac OsX, so Tk has little control over them.
--
+------------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+------------------------------------------------------------------------+
I am on windows, but I would line my popup menus to change their
colours following the theme ttk::menubutton generates a nice themed
menubutton but when you click on it you get a horrible menu dropping
down in the middle of my application with a nice theme.
All I need to find are the 4 colours needed to set on the menu I was
not hoping to have themed menus just the same colour scheme.
There does not seem to be a 'Theme independant' way to find fg, bg,
activefg and activebg.
Martyn
If you write "in the middle of my application, you are perhaps
complaining about the following tk bugs:
http://sourceforge.net/tracker/?func=detail&aid=3306909&group_id=12997&atid=112997
To temporarely fix this, I source within my application the following
code:
* First proc beautifies, second fixes
* By the way, the patch did not make it in tcl8.5.10, did it ?
if {0 >= [package vcompare 8.5.9 [package require Tk]]} {
proc ttk::menubutton::PostPosition {mb menu} {
set x [winfo rootx $mb]
set y [winfo rooty $mb]
set dir [$mb cget -direction]
set bw [winfo width $mb]
set bh [winfo height $mb]
set mw [winfo reqwidth $menu]
set mh [winfo reqheight $menu]
set sw [expr {[winfo screenwidth $menu] - $bw - $mw}]
set sh [expr {[winfo screenheight $menu] - $bh - $mh}]
switch -- $dir {
above { if {$y >= $mh} { incr y -$mh } { incr y $bh } }
below { if {$y <= $sh} { incr y $bh } { incr y -$mh } }
left { if {$x >= $mw} { incr x -$mw } { incr x $bw } }
right {
if {$x <= $sw} { incr x $bw } { incr x -$mw }
}
flush {
# post menu atop menubutton.
# If there's a menu entry whose label matches the
# menubutton -text, assume this is an optionmenu
# and place that entry over the menubutton.
set index [FindMenuEntry $menu [$mb cget -text]]
if {$index ne ""} {
incr y -[$menu yposition $index]
}
}
}
# Align the lower ends of button and menu, if no place to show menu
# downwards
if { $dir in {"left" "right"} && $y >= $sh } {
set y [expr {$y-$mh+$bh}]
}
return [list $x $y]
}
proc ::tk::PostOverPoint {menu x y {entry {}}} {
global tcl_platform
if {$entry ne ""} {
if {$entry == [$menu index last]} {
incr y [expr {-([$menu yposition $entry] \
+ [winfo reqheight $menu])/2}]
} else {
incr y [expr {-([$menu yposition $entry] \
+ [$menu yposition [expr {$entry+1}]])/2}]
}
incr x [expr {-[winfo reqwidth $menu]/2}]
}
if {$tcl_platform(platform) == "windows" && $tcl_platform(osVersion)
< 6.0} {
# We need to fix some problems with menu posting on Windows,
# where, if the menu would overlap top or bottom of screen,
# Windows puts it in the wrong place for us. We must also
# subtract an extra amount for half the height of the current
# entry. To be safe we subtract an extra 10.
set yoffset [expr {[winfo screenheight $menu] \
- $y - [winfo reqheight $menu] - 10}]
if {$yoffset < 0} {
# The bottom of the menu is offscreen, so adjust upwards
incr y $yoffset
if {$y < 0} { set y 0 }
}
# If we're off the top of the screen (either because we were
# originally or because we just adjusted too far upwards),
# then make the menu popup on the top edge.
if {$y < 0} {
set y 0
}
}
$menu post $x $y
if {$entry ne "" && [$menu entrycget $entry -state] ne "disabled"} {
$menu activate $entry
GenerateMenuSelect $menu
}
}
}
What did you try? Doesn't the following work?
% ttk::style theme use clam
% ttk::style lookup TMenubutton -background
#dcdad5
% ttk::style lookup TMenubutton -foreground
black
% ttk::style lookup TMenubutton -background active
#eeebe7
% ttk::style lookup TMenubutton -foreground active
black
--Koen
Thanks,
I was using
ttk::style configure . -activebackground
which for some themes returns an empty string
Martyn
> I was using
> ttk::style configure . -activebackground
> which for some themes returns an empty string
Does a toplevel have an activebackground property?
Donald Arseneau as...@triumf.ca