[issue22214] Tkinter: Don't stringify callback arguments

Terry J. Reedy report at bugs.python.org
Sun Jun 19 16:26:36 EDT 2016


Terry J. Reedy added the comment:

There is no review button for the new patch (don't know why), so: in the News and What's New entries, change "if call" to "if one calls" and "or set" to "or sets".

More importantly, question your use of 'callback' in the entries.  To me, a callback is a function that is passed to a recipient to be called *by the recipient* at some later time. For tkinter, there are command callbacks, which get no arguments, validatecommand callbacks, which get string arguments, event callbacks, which get a tkinter event object as argument, and after callbacks, which get as arguments the Python objects given to the after call.  In all cases, there is no visible issue of passing non-strings as strings to the callback.  The following duplicates the testfunc and interp.call in test_tcl.py as closely as I know how, but with a different result.

import tkinter as tk
root = tk.Tk()
def test(*args):
    for arg in args:
        print(type(arg), '', repr(arg))
root.after(1, test, True, 1, '1')
root.mainloop()

To me, the revised test does not involve a callback.  The test registers a name for the python function so it can be passes by name to Tk().call, as required by the .call signature.  So I would replace 'callback' with 'Python function registered with tk'.

Registered functions can, of course, be used as callback if they have the proper signature.  ConfigDialog registers an 'is_int' function so it can be passed to an Entry as a validatecommand callback.  The patch does not affect registered validate commands because they receive string args.

After grepping idlelib for "register(", I believe this is the only function IDLE registers with tk (two of its classes have non-tk .register methods).  Hence, IDLE should not be affected by the patch and seems not as far as I tested.

I can't properly review the _tkinter patch as it requires too much knowledge of tcl/tk interfaces.

----------
title: Tkinter: Don't stringify callbacks arguments -> Tkinter: Don't stringify callback arguments

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22214>
_______________________________________


More information about the Python-bugs-list mailing list