diff options
author | Guido van Rossum <guido@python.org> | 1996-09-05 16:45:49 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-09-05 16:45:49 (GMT) |
commit | e1a7a3b3b349ffd24cf25593a446e9f9bec9d615 (patch) | |
tree | 0077485c7a9992c604f778b4b15c9cc7011d3b16 | |
parent | 932c06e4ff78a095df7a5e2678b8c0da7ad74b45 (diff) | |
download | cpython-e1a7a3b3b349ffd24cf25593a446e9f9bec9d615.zip cpython-e1a7a3b3b349ffd24cf25593a446e9f9bec9d615.tar.gz cpython-e1a7a3b3b349ffd24cf25593a446e9f9bec9d615.tar.bz2 |
Add initial values to variables to avoid crash in __del__
-rw-r--r-- | Lib/lib-tk/Tkinter.py | 6 | ||||
-rwxr-xr-x | Lib/tkinter/Tkinter.py | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index b241f06..f43e3d6 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -76,6 +76,7 @@ def _exit(code='0'): _varnum = 0 class Variable: + _default = "" def __init__(self, master=None): global _default_root global _varnum @@ -85,6 +86,7 @@ class Variable: self._tk = _default_root.tk self._name = 'PY_VAR' + `_varnum` _varnum = _varnum + 1 + self.set(self._default) def __del__(self): self._tk.globalunsetvar(self._name) def __str__(self): @@ -93,24 +95,28 @@ class Variable: return self._tk.globalsetvar(self._name, value) class StringVar(Variable): + _default = "" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.globalgetvar(self._name) class IntVar(Variable): + _default = "0" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.getint(self._tk.globalgetvar(self._name)) class DoubleVar(Variable): + _default = "0.0" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.getdouble(self._tk.globalgetvar(self._name)) class BooleanVar(Variable): + _default = "false" def __init__(self, master=None): Variable.__init__(self, master) def get(self): diff --git a/Lib/tkinter/Tkinter.py b/Lib/tkinter/Tkinter.py index b241f06..f43e3d6 100755 --- a/Lib/tkinter/Tkinter.py +++ b/Lib/tkinter/Tkinter.py @@ -76,6 +76,7 @@ def _exit(code='0'): _varnum = 0 class Variable: + _default = "" def __init__(self, master=None): global _default_root global _varnum @@ -85,6 +86,7 @@ class Variable: self._tk = _default_root.tk self._name = 'PY_VAR' + `_varnum` _varnum = _varnum + 1 + self.set(self._default) def __del__(self): self._tk.globalunsetvar(self._name) def __str__(self): @@ -93,24 +95,28 @@ class Variable: return self._tk.globalsetvar(self._name, value) class StringVar(Variable): + _default = "" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.globalgetvar(self._name) class IntVar(Variable): + _default = "0" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.getint(self._tk.globalgetvar(self._name)) class DoubleVar(Variable): + _default = "0.0" def __init__(self, master=None): Variable.__init__(self, master) def get(self): return self._tk.getdouble(self._tk.globalgetvar(self._name)) class BooleanVar(Variable): + _default = "false" def __init__(self, master=None): Variable.__init__(self, master) def get(self): |