struggling with style (ttk::entry)

136 views
Skip to first unread message

Matthias Meier

unread,
Sep 5, 2011, 10:10:28 AM9/5/11
to
Hello,

I started to test ttk / style.


To modify the entries i tested

ttk::style configure TEntry -borderwidth 3 -foreground blue

and borderwith/foreground changed as i expected.

But with

ttk::style configure TEntry -relief flat

nothing happens (and no error is shown). Why?


(tk8.5.10 on linux)

Thanks,
Matthias


Schelte Bron

unread,
Sep 5, 2011, 5:45:07 PM9/5/11
to
Matthias Meier wrote:
> But with
>
> ttk::style configure TEntry -relief flat
>
> nothing happens (and no error is shown). Why?
>
When using ttk it matters a lot which theme you are using. Since you
didn't mention that, I'm going to assume you are using the "default"
theme.

One of the first things to do when investigating ttk widgets is to
dump the layout using: ttk::style layout TEntry
That returns (after some formatting):
Entry.field -sticky nswe -border 1 -children {
Entry.padding -sticky nswe -children {
Entry.textarea -sticky nswe
}
}

A little source-diving shows that none of these elements (field,
padding, or textarea) recognize the -relief option. However the
border element does. So we can just replace the field element with
the border element in the layout (don't use both because they both
react to the borderwidth option):
ttk::style layout TEntry {
Entry.border -sticky nswe -border 1 -children {
Entry.padding -sticky nswe -children {
Entry.textarea -sticky nswe
}
}
}

The border element takes its background color from the -background
option while the field element uses the -fieldbackground option. To
compensate for that, copy -fieldbackground to -background:
ttk::style configure TEntry -background \
[ttk::style configure TEntry -fieldbackground]

Now your ttk::entries will respond to the -relief option.

Of course that still doesn't give you the ability to change the
color of the border that you are looking for, according to your
other post. To do that make your own element from an image:
image create photo border -width 20 -height 20
border put red -to 0 0 19 19
border put white -to 2 2 17 17
ttk::style element create Redborder image border -border 3
ttk::style layout TEntry {
Redborder -sticky nswe -border 1 -children {
Entry.padding -sticky nswe -children {
Entry.textarea -sticky nswe
}
}
}


Schelte.

Reply all
Reply to author
Forward
0 new messages