Version 5 of ttk::entry

Updated 2015-02-25 08:02:01 by oehhar

Ttk's entry widget. Follows the standard pattern for widget constructors

ttk::entry widgetName ?options…?

Documented at:

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