:Robert
What you would usually do is create a custom style derived from the
original TEntry widget class. You don't have to do that if you want
all entry widgets in your application to have the new behavior, but
for the moment I'll assume you only have a few entry widgets that
are supposed to work this way.
For the custom style you create a map of the attributes that should
change when the data is wrong:
style map Validate.TEntry -foreground {invalid red} \
-fieldbackground {invalid yellow}
Now by simply changing the invalid state of the entry the colors
will change:
ttk::entry .entry1 -style Validate.TEntry -validate all \
-validatecommand {
if {[string is digit %P]} {
%W state !invalid
} else {
%W state invalid
}
return 1
}
pack .entry1
Note that in some themes it may really not be possible to change the
background color of an entry widget. The code shown above works
fine on linux with the "default" theme.
Schelte.
--
set Reply-To [string map {nospam schelte} $header(From)]
.e1 configure -bg "yellow"
focus .e1
I can deal though...I hope there is a book or something. Or the Welch
book is updated for this (as well as other things).
:Robert
It's not really that much more complicated. All that has really changed
is that you have so set-up the new style (the single [style map ...]
line), and then you use [.e1 state invalid] instead of [.e1 configure
... various options]. I'd say it makes the code clearer too.
-- Neil
.e1 state invalid
focus .e1
So, it's less complex I would say.
But yes...I can see tiles way as being nice.
Robert
To come back to your question about documentation. There is a nice
introduction into the tile widget set at:
http://tktable.sourceforge.net/tile/tile-tcl2004.pdf
Your answer was better than my question...
:Robert
The ttk::entry widget has '-background' and '-foreground' options,
but they're not documented, because at the moment '-background'
doesn't work ('-foreground' does, though).
But see also the approach Schelte Bron describes in
(using [$e state invalid/!invalid] and [style map]).
--Joe English
True. For the simple cases ("I just want a yellow entry widget"),
it takes a lot more work in Tile than it does with the standard
Tk widgets.
But things are often not that simple. A more common use case is:
"I want entry widgets to be black on white normally, red on yellow
if the text is invalid, black on light grey if the widget is readonly,
and dark gray on light grey if it's disabled. On Windows, readonly
widgets should use the system background color from the users's chosen
color scheme instead of light gray; ditto for the foreground color in
disabled widgets. Same thing for OSX."
This is where the Tile theme engine starts to make things a lot easier.
(For an extreme example: take a look at how much work the core Tk
[button] implementation does to decide what the -relief should be.
This sort of thing is a *lot* simpler in Tile.)
[ttk::label]s and [ttk::frame]s still support the simple use cases
("I just want a yellow label"), and, as of a couple weeks ago,
in CVS, it even works correctly :-). [ttk::entry] widgets will
support this sort of thing too once I can get rid of some historical
baggage (a fight with Gnome and KDE that I finally figured out how
to win...)
For other Tile widgets (notably buttons), you'll still have
to do things the hard way -- but note that the "easy" way
(".b configure -bg red") doesn't *really* work with the core
widgets either.
--Joe English