Version 3 of ttk::entry

Updated 2011-10-06 07:17:50 by oehhar

Ttk's entry widget.

http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_entry.htm

  -relief and custom border color for ttk::entry

Schelte Bron described on clt how to add a -relief option to a ttk::entry widget:

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

  Change Entire Button Background Rather than Just the Border on XPNative Theme

Question on clt :

I saw a post where someone edited the elements and style layout on an entry to change the behavior. I was wondering if there is a way to use elements to change the behavior of the XPNative theme for TButton style? When you set the background color, it only sets the border on the button for XPNative. I would like the entire background to be set. Is this impossible or can a new style with newly defined elements fix this to work as expected for this theme?

Answer by Pat Thoyts:

See http://paste.tclers.tk/2534 and an earlier version at http://paste.tclers.tk/43