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

Custom ttk styles

144 views
Skip to first unread message

Googie

unread,
Oct 7, 2010, 6:16:13 AM10/7/10
to
Hi,

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

Pat Thoyts

unread,
Oct 7, 2010, 7:06:13 AM10/7/10
to
Googie <n...@sp4m.c0m> writes:

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

Googie

unread,
Oct 8, 2010, 3:22:48 AM10/8/10
to
W dniu 2010-10-07 13:06, Pat Thoyts pisze:

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

That did the job. Thanks!

Regards,
Googie

Googie

unread,
Oct 7, 2010, 5:01:45 PM10/7/10
to
On 7 Paź, 13:06, Pat Thoyts <pattho...@users.sourceforge.net> wrote:
> 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.
[...]

> --
> Pat Thoyts                            http://www.patthoyts.tk/
> PGP fingerprint 2C 6E 98 07 2C 59 C8 97  10 CE 11 E6 04 E0 B9 DD

Thanks! That did the job.

Regards,
Googie

0 new messages