I just started playing with custom ttk styles.
I want to create custom style named TImgcheckbutton which is somehow
similar to TCheckbutton, but yet different. I want to apply it to
explicity defined widgets using -style option.
Currently I have this code in global namespace:
ttk::style layout TImgcheckbutton {
TImgcheckbutton.border -children {
TImgcheckbutton.padding -sticky nswe -children {
TImgcheckbutton.label -sticky nswe
}
}
}
ttk::style map TImgcheckbutton -relief [list disabled flat pressed
sunken active raised]
ttk::style configure TImgcheckbutton -padding 2 -relief flat
But when I try to create widget with such style, Tk complains that it
doesn't know TImgcheckbutton style. Why? Where should I put it? What
about switching ttk themes during runtime? Will it work or should I
re-execute this code for each theme set?
Regards,
Googie
You need to define this in each theme that gets used. Either you make
versions for each theme or you can call a setup on <<ThemeChanged>> as
shown below. Or you can iirc defin your style in the 'default' theme and
things will see it there.
The following works for me giving a customised checkbutton that shows no
indicator but just a ridge when it is selected.
package require Tk 8.5
proc InitCustomCheckbutton {} {
ttk::style layout Custom.Checkbutton {
Custom.Checkbutton.border -children {
Custom.Checkbutton.padding -sticky news -children {
Custom.Checkbutton.label -sticky news
}
}
}
ttk::style configure Custom.Checkbutton {*}[ttk::style configure
TCheckbutton] -relief flat
ttk::style map Custom.Checkbutton {*}[ttk::style map TCheckbutton] \
-relief {disabled flat pressed sunken active raised {selected
!disabled} ridge}
if {[lsearch -exact [bind . <<ThemeChanged>>] InitCustomCheckbutton] == -1} {
bind . <<ThemeChanged>> +InitCustomCheckbutton
}
}
proc Test {} {
ttk::checkbutton .c1 -text Normal -variable ::check
ttk::checkbutton .c2 -text Custom -variable ::check\
-style Custom.Checkbutton
pack .c1 .c2 -side top -fill x
}
--
Pat Thoyts http://www.patthoyts.tk/
PGP fingerprint 2C 6E 98 07 2C 59 C8 97 10 CE 11 E6 04 E0 B9 DD
That did the job. Thanks!
Regards,
Googie
Thanks! That did the job.
Regards,
Googie