Callback functions arguments

ast nomail at
Tue Oct 28 08:35:01 CET 2014

"Peter Otten" <__peter__ at> a écrit dans le message de 
news:mailman.15231.1414399974.18130.python-list at

Tanks for you answer

> Python doesn't "know" it has to pass an argument, it just does it. Change
> the callback to
> def maj():
>    print("no args")
> and you'll get an error. If I were to guess

Yes you are right. I got an error:

TypeError: maj() takes 0 positional arguments but 1 was given

OK, but i still find very strange the choice of Python's designers to
make the Scale behaves like that.
The position of the scale is in variable Valeur  (StringVar()) which
cold be read/write from anywhere, so it is not necessary to pass
this variable as an argument to the call back function.

If you are looking at the SpinBox widget, in example 4 in the
same web site:

boite = Spinbox(Mafenetre,from_=0,to=10,increment=0.5, \

with the callback function "carre"

def carre():
    """ Calcul du carré """
    Resultat.set("Carré = "+str(float(Valeur.get())**2))

you can notice that carre function has no arguments. The value
in the SpinBox is catched with Valeur variable.

So SpinBox and Scale behaves differently. It is strange.

> you probably are misled by the 'command=maj' part in the above line.

no, I understood this mechanism 

More information about the Python-list mailing list