----- Original Message -----
> From: "ast" <nom...@invalid.com>
> To: python-list@python.org
> Sent: Monday, 27 October, 2014 9:16:26 AM
> Subject: Callback functions arguments
> 
> Hi
> 
> In this web site at example n°5
> http://fsincere.free.fr/isn/python/cours_python_tkinter.php
> 
> A program is using the "Scale" widget from tkinter module.
> Here is a piece of code:
> 
> Valeur = StringVar()
> 
> echelle = Scale(Mafenetre, from_=-100, to=100, resolution=10, \
> orient=HORIZONTAL, length=300, width=20, label="Offset", \
> tickinterval=20, variable=Valeur, command=maj)
> 
> The "maj" callback function is:
> 
> def maj(nouvelleValeur):
>     print(nouvelleValeur)
> 
> When the user move the scale with the mouse, the new position
> is supposed to be printed on the python shell.
> 
> The "maj" function has an argument "nouvelleValeur" but no
> argument is passed through the Scale widget.
> 
> So how the hell Python knows that it has to pass parameter
> "Valeur" to the "maj" function ?
> 
> thx

The Scale object is performing the call, hence it will be the Scale object that 
will call your maj function with a "nouvelleValeur" parameter.

When you write command=maj, you pass the function, but you don't call it. 
That's the purpose of a callback. You provide a function and it get called by 
the object you've been giving the function to. The Scale object should be 
documented and should provide with the callback signature.

See http://effbot.org/zone/tkinter-callbacks.htm

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be 
privileged. If you are not the intended recipient, please notify the sender 
immediately and do not disclose the contents to any other person, use it for 
any purpose, or store or copy the information in any medium. Thank you.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to