[Tkinter-discuss] StringVar fails to honor None

Russell Adams RLAdams at AdamsInfoServ.Com
Fri Jan 18 09:19:35 CET 2013


On Fri, Jan 18, 2013 at 08:49:40PM +1300, Greg Ewing wrote:
> >On Thu, Jan 17, 2013 at 11:59:00AM +0100, Michael Lange wrote:
>
> >>apparently globalsetvar() tries its best to convert anything it gets into
> >>a string.
>
> Since strings are the only thing a tcl variable can hold,
> it doesn't have much choice, really.
>
> If you want to store an arbitrary Python value without it
> getting munged, a tcl variable is probably the wrong thing
> to use.

I found this making a form with SQL-Alchemy. I used the object
returned for my row from SQL-A to set the initial values on my Tkinter
form. I created a "Revert" button to essentially undo any data entry
and go back to that SQL-A data. Revert revealed the behavior, which
made no sense at the time because I had passed a None unwittingly as
an initial value (from a NULL SQL row converted to None), and I set it
back to the same SQL-A object's value.

I thought I'd made a mistake somewhere and converted to string,
obviously I hadn't. Now I've just added some code to convert None to
'', and let it be.

Thanks.

------------------------------------------------------------------
Russell Adams                            RLAdams at AdamsInfoServ.com

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

Fingerprint:    1723 D8CA 4280 1EC9 557F  66E8 1154 E018 1160 DCB3


More information about the Tkinter-discuss mailing list