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 *