Why only some Tkinter callback functions need to have an argument but others don't Why only some Tkinter callback functions need to have an argument but others don't tkinter tkinter

Why only some Tkinter callback functions need to have an argument but others don't


Scale doesn't take an event. It takes the current value. Try this:

def cmd(value):    print int(value)

If you read the Tk tutorial, it explains this:

There is a "command" configuration option, which lets you specify a script to call whenever the scale is changed. Tk will automatically append the current value of the scale as a parameter each time it invokes this script (we saw a similar thing with extra parameters being added to scrollbar callbacks and those on the widgets they scroll).

Or, if you read the actual manpage:

Specifies the prefix of a Tcl command to invoke whenever the scale's value is changed via a widget command. The actual command consists of this option followed by a space and a real number indicating the new value of the scale.

In other words, the way to distinguish them is to read the docs. Unfortunately, the Tkinter docs aren't all that complete—they assume you already know how Tcl/Tk works, or how to look it up yourself. That's why the docs start off with a list of links to sources of Tk documentation.

If you prefer to figure it out by trial and error, it's not that hard to see what gets passed:

def cmd(*args):    print('Scale command says {}'.format(args))def enable(*args):    print('Button command says {}'.format(args))

But this won't always tell you everything you need to know; there are other callbacks whose arguments aren't obvious enough to figure out without a lot more work, or which are configurable (e.g., the validate callback).


When you set up a binding (with the bind) command, the callback always is given an event object.

When you are working with the command attribute of a widget, different widgets send different information to the command. In this case they never send an event, but they will send other types of data. This is simply due to the fact different commands do different things.

The scale widget is no different -- you claim the callback takes an event, but that is false. It is passed the current value of the scale widget rather than an event object.