"Peter Otten" <__pete...@web.de> a écrit dans le message de news:mailman.15231.1414399974.18130.python-l...@python.org...


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:
http://fsincere.free.fr/isn/python/cours_python_tkinter.php

boite = Spinbox(Mafenetre,from_=0,to=10,increment=0.5, \
textvariable=Valeur,width=5,command=carre)

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
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to