[Tkinter-discuss] StringVar fails to honor None

Michael Lange klappnase at web.de
Thu Jan 17 20:20:46 CET 2013

On Thu, 17 Jan 2013 12:52:36 -0600
Russell Adams <RLAdams at AdamsInfoServ.Com> wrote:

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

There is the Variable's _default attribute, but I don't think that
it helps much, and since it is a "hidden" attribute, I don't think using
it could be considered "proper"

In your case maybe creating a custom StringVar class with a modified
set() might be the most handy approach, like:

class MyStringVar(StringVar):
    def __init__(self, *args, **kw):
        StringVar.__init__(self, *args, **kw)
    def set(self, value):
        if value is None:
            value = ''
        return StringVar.set(self, value)



.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

You can't evaluate a man by logic alone.
		-- McCoy, "I, Mudd", stardate 4513.3

More information about the Tkinter-discuss mailing list