Mailing List Archive

IntVar - to detect a change in it
Is there anyway an altering of a variable (Int-, String- or Double-)
(by the user, via the GUI) could call a function in order to tell the
environment that it has changed since the initial setting(or a static
comparison value)

Ole-Kr. Villaboe


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
IntVar - to detect a change in it [ In reply to ]
Ole-Kristian Villaboe wrote:

> Is there anyway an altering of a variable (Int-, String- or Double-)
> (by the user, via the GUI) could call a function in order to tell the
> environment that it has changed since the initial setting(or a static
> comparison value)
>
> Ole-Kr. Villaboe
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.

You could use the lostfocus event of the widget

Pierrette
IntVar - to detect a change in it [ In reply to ]
Ole-Kristian Villaboe <olevi@my-deja.com> wrote:
> Is there anyway an altering of a variable (Int-, String- or Double-)
> (by the user, via the GUI) could call a function in order to tell the
> environment that it has changed since the initial setting(or a static
> comparison value)

Assuming you're talking about Tkinter here: below's an example of using
trace() to trace a variable:

class VLabel(Label):
"""VLabel class - becomes red when textvariable.valid() returns
false"""

def __init__(self, master, textvariable, **cnf):
apply(Label.__init__, (self, master), cnf)
self.config(textvariable=textvariable)
self.textvariable = textvariable
textvariable.trace('w',self.notify)

def notify(self, *args):
if self.textvariable.valid():
self.config(bg=self.config('bg')[3])
else:
self.config(bg='red')

Everytime the textvariable is changed notify() gets called, which checks
whether the textvariable is valid. If not, the background is colored red,
if it is valid, the background is set to its default color.

HTH, Frank
--
The last ever dolphin message was misinterpreted as a surprisingly
sophisticated attempt to do a double-backwards-somersault through a hoop
whilst whistling the "Star Sprangled Banner", but in fact the message was
this: So long and thanks for all the fish.
-- Douglas Adams, 'The Hitch Hiker's Guide to the Galaxy'