mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
c9ba38c21c
commit
9a6e201f7d
6 changed files with 58 additions and 17 deletions
|
@ -1929,19 +1929,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)
|
||||
|
@ -2854,7 +2859,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},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue