From 70c3dda2fba35f08f32163bc03315834d165cb36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Wed, 22 Jan 2003 09:17:38 +0000 Subject: [PATCH] Convert booleans to integers in IntVar.set. Fixes #671741. Return booleans from _tkinter.getboolean. Convert booleans to Tcl booleans in AsObj. --- Lib/lib-tk/Tkinter.py | 6 ++++++ Modules/_tkinter.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Lib/lib-tk/Tkinter.py b/Lib/lib-tk/Tkinter.py index de41bdcad5d..bd80c3b6050 100644 --- a/Lib/lib-tk/Tkinter.py +++ b/Lib/lib-tk/Tkinter.py @@ -234,6 +234,12 @@ class IntVar(Variable): MASTER can be given as master widget.""" Variable.__init__(self, master) + def set(self, value): + """Set the variable to value, converting booleans to integers.""" + if isinstance(value, bool): + value = int(value) + return Variable.set(self, value) + def get(self): """Return the value of the variable as an integer.""" return getint(self._tk.globalgetvar(self._name)) diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 8b9926e0be4..b9dc179eee3 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -868,6 +868,8 @@ AsObj(PyObject *value) if (PyString_Check(value)) return Tcl_NewStringObj(PyString_AS_STRING(value), PyString_GET_SIZE(value)); + else if (PyBool_Check(value)) + return Tcl_NewBooleanObj(PyObject_IsTrue(value)); else if (PyInt_Check(value)) return Tcl_NewLongObj(PyInt_AS_LONG(value)); else if (PyFloat_Check(value)) @@ -1739,7 +1741,7 @@ Tkapp_GetBoolean(PyObject *self, PyObject *args) return NULL; if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR) return Tkinter_Error(self); - return Py_BuildValue("i", v); + return PyBool_FromLong(v); } static PyObject *