On Thu, Jan 17, 2013 at 11:59:00AM +0100, Michael Lange wrote:
> Hi Russell,
>
> On Wed, 16 Jan 2013 17:11:52 -0600
> Russell Adams <rlad...@adamsinfoserv.com> wrote:
>
> > Found this while reverting a data entry form to database values (ie:
> > Undo), all my fields became "None". Set changes None to a string,
> > creating with value= doesn't.
> >
> > Seems inconsistent, is this intentional or to be expected?
>
> this seems like a feature or a bug in tkapp.globalsetvar().
>
> When we look at Variable.__init_(), we find:
>
> class Variable:
>     def __init__(self, master=None, value=None, name=None):
>         (...)
>         if value is not None:
>             self.set(value)
>
> so if value == None, value actually won't be applied.
> Now in set() it is simply:
>
>     def set(self, value):
>         """Set the variable to VALUE."""
>         return self._tk.globalsetvar(self._name, value)
>
> apparently globalsetvar() tries its best to convert anything it gets into
> a string.
> This is probably useful in most cases (for example when we pas
> an integer or a float to set()), but shows odd results sometimes. Setting
> the StringVar to boolean True or False e.g. actually sets its value to
> "1" or "0" ;)
> If I pass an empty dict or list to set(), I get the strings
> "{}" or "[]", which seems at least to be consistent with the behavior of
> set (None).
>

I can appreciate that. Is there a "proper" way to reset a Variable to
it's original state?

Thanks.

> I guess this is one of the tkinter oddities we have to live with, at
> least I don't see how this should be fixed without breaking existing
> code.
>
> Regards
>
> Michael
>
>
>
> .-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.
>
> Violence in reality is quite different from theory.
>               -- Spock, "The Cloud Minders", stardate 5818.4
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss@python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>


------------------------------------------------------------------
Russell Adams                            rlad...@adamsinfoserv.com

PGP Key ID:     0x1160DCB3           http://www.adamsinfoserv.com/

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to