summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-12-26 18:06:43 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-12-26 18:06:43 (GMT)
commit1b97ed5abcad78c9513d605f0cb6b1936599a7b2 (patch)
treeec7158e2c59224072d51eab279d422e72c85dd86 /Lib
parente575148cc23283f72aeeb0bff4a9343ce738aa92 (diff)
parentd97c01ff2897a1d706b13d3684f8db69c8ea2ef3 (diff)
downloadcpython-1b97ed5abcad78c9513d605f0cb6b1936599a7b2.zip
cpython-1b97ed5abcad78c9513d605f0cb6b1936599a7b2.tar.gz
cpython-1b97ed5abcad78c9513d605f0cb6b1936599a7b2.tar.bz2
Issue #20067: Tkinter variables now work when wantobjects is false.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/tkinter/__init__.py6
-rw-r--r--Lib/tkinter/test/test_tkinter/test_variables.py15
2 files changed, 12 insertions, 9 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 68cf1b3..73fca8f 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -220,12 +220,12 @@ class Variable:
_varnum += 1
if value is not None:
self.initialize(value)
- elif not self._tk.call("info", "exists", self._name):
+ elif not self._tk.getboolean(self._tk.call("info", "exists", self._name)):
self.initialize(self._default)
def __del__(self):
"""Unset the variable in Tcl."""
- if (self._tk is not None and self._tk.call("info", "exists",
- self._name)):
+ if (self._tk is not None and
+ self._tk.getboolean(self._tk.call("info", "exists", self._name))):
self._tk.globalunsetvar(self._name)
def __str__(self):
"""Return the name of the variable in Tcl."""
diff --git a/Lib/tkinter/test/test_tkinter/test_variables.py b/Lib/tkinter/test/test_tkinter/test_variables.py
index 378cc92..fa1f898 100644
--- a/Lib/tkinter/test/test_tkinter/test_variables.py
+++ b/Lib/tkinter/test/test_tkinter/test_variables.py
@@ -24,6 +24,9 @@ class TestBase(unittest.TestCase):
class TestVariable(TestBase):
+ def info_exists(self, *args):
+ return self.root.getboolean(self.root.call("info", "exists", *args))
+
def test_default(self):
v = Variable(self.root)
self.assertEqual("", v.get())
@@ -35,21 +38,21 @@ class TestVariable(TestBase):
self.assertEqual("varname", str(v))
def test___del__(self):
- self.assertFalse(self.root.call("info", "exists", "varname"))
+ self.assertFalse(self.info_exists("varname"))
v = Variable(self.root, "sample string", "varname")
- self.assertTrue(self.root.call("info", "exists", "varname"))
+ self.assertTrue(self.info_exists("varname"))
del v
- self.assertFalse(self.root.call("info", "exists", "varname"))
+ self.assertFalse(self.info_exists("varname"))
def test_dont_unset_not_existing(self):
- self.assertFalse(self.root.call("info", "exists", "varname"))
+ self.assertFalse(self.info_exists("varname"))
v1 = Variable(self.root, name="name")
v2 = Variable(self.root, name="name")
del v1
- self.assertFalse(self.root.call("info", "exists", "name"))
+ self.assertFalse(self.info_exists("name"))
# shouldn't raise exception
del v2
- self.assertFalse(self.root.call("info", "exists", "name"))
+ self.assertFalse(self.info_exists("name"))
def test___eq__(self):
# values doesn't matter, only class and name are checked