summaryrefslogtreecommitdiffstats
path: root/Modules/_tkinter.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-04 09:44:30 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-04 09:44:30 (GMT)
commit06e66108c6c71e1cc2b6a0c1d4cd8d245469632f (patch)
tree538f1b9c7cb6dd16720000b232038d17ad0f3dbd /Modules/_tkinter.c
parent46ba6c8563922f043cad6423202ee0119614c807 (diff)
parent9a6e201f7d5f147b776274c1598089fc68859e98 (diff)
downloadcpython-06e66108c6c71e1cc2b6a0c1d4cd8d245469632f.zip
cpython-06e66108c6c71e1cc2b6a0c1d4cd8d245469632f.tar.gz
cpython-06e66108c6c71e1cc2b6a0c1d4cd8d245469632f.tar.bz2
Issue #15133: _tkinter.tkapp.getboolean() now supports Tcl_Obj and always
returns bool. tkinter.BooleanVar now validates input values (accepted bool, int, str, and Tcl_Obj). tkinter.BooleanVar.get() now always returns bool.
Diffstat (limited to 'Modules/_tkinter.c')
-rw-r--r--Modules/_tkinter.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 29cf233..241c1a0 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -1934,19 +1934,24 @@ Tkapp_GetDouble(PyObject *self, PyObject *args)
}
static PyObject *
-Tkapp_GetBoolean(PyObject *self, PyObject *args)
+Tkapp_GetBoolean(PyObject *self, PyObject *arg)
{
char *s;
int v;
- if (PyTuple_Size(args) == 1) {
- PyObject *o = PyTuple_GetItem(args, 0);
- if (PyLong_Check(o)) {
- Py_INCREF(o);
- return o;
- }
+ if (PyLong_Check(arg)) { /* int or bool */
+ return PyBool_FromLong(Py_SIZE(arg) != 0);
}
- if (!PyArg_ParseTuple(args, "s:getboolean", &s))
+
+ if (PyTclObject_Check(arg)) {
+ if (Tcl_GetBooleanFromObj(Tkapp_Interp(self),
+ ((PyTclObject*)arg)->value,
+ &v) == TCL_ERROR)
+ return Tkinter_Error(self);
+ return PyBool_FromLong(v);
+ }
+
+ if (!PyArg_Parse(arg, "s:getboolean", &s))
return NULL;
CHECK_STRING_LENGTH(s);
if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR)
@@ -2862,7 +2867,7 @@ static PyMethodDef Tkapp_methods[] =
{"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS},
{"getint", Tkapp_GetInt, METH_VARARGS},
{"getdouble", Tkapp_GetDouble, METH_VARARGS},
- {"getboolean", Tkapp_GetBoolean, METH_VARARGS},
+ {"getboolean", Tkapp_GetBoolean, METH_O},
{"exprstring", Tkapp_ExprString, METH_VARARGS},
{"exprlong", Tkapp_ExprLong, METH_VARARGS},
{"exprdouble", Tkapp_ExprDouble, METH_VARARGS},