Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #79775

Re: Callback functions arguments

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <prvs=3703a34d2=jeanmichel@sequans.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.093
X-Spam-Evidence '*H*': 0.82; '*S*': 0.00; 'argument': 0.05; 'tkinter': 0.07; 'arguments': 0.09; 'callback': 0.09; 'function,': 0.09; 'parameter': 0.09; 'thx': 0.09; 'python': 0.11; 'def': 0.12; 'parameter.': 0.16; 'widget': 0.19; 'example': 0.22; 'documented': 0.24; 'performing': 0.26; 'pass': 0.26; 'code:': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'scale': 0.29; 'piece': 0.31; 'supposed': 0.32; 'url:python': 0.33; '-----': 0.33; 'monday,': 0.33; 'knows': 0.35; 'but': 0.35; 'module.': 0.36; 'url:org': 0.36; 'should': 0.36; 'email addr:python.org': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'called': 0.40; 'how': 0.40; 'new': 0.61; 'you.': 0.62; "you've": 0.63; 'information': 0.63; 'received:194': 0.64; 'provide': 0.64; 'email name:python-list': 0.65; 'here': 0.66; 'notice:': 0.67; 'person,': 0.68; 'privileged.': 0.69; 'url:htm': 0.73; 'disclose': 0.74; 'url:free': 0.84; 'url:php': 0.85; 'medium.': 0.91; 'url:fr': 0.93
X-IronPort-AV E=Sophos;i="5.04,794,1406584800"; d="scan'208";a="3509659"
Date Mon, 27 Oct 2014 11:19:17 +0100 (CET)
From Jean-Michel Pichavant <jeanmichel@sequans.com>
To python-list@python.org
In-Reply-To <544dff5d$0$2073$426a74cc@news.free.fr>
Subject Re: Callback functions arguments
MIME-Version 1.0
X-Mailer Zimbra 7.2.7_GA_2942 (ZimbraWebClient - GC37 (Linux)/7.2.7_GA_2942)
Content-Type text/plain; charset="utf-8"
Content-Transfer-Encoding base64
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15232.1414405179.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1414405179 news.xs4all.nl 2853 [2001:888:2000:d::a6]:38660
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:79775

Show key headers only | View raw


----- Original Message -----
> From: "ast" <nomail@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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Callback functions arguments Jean-Michel Pichavant <jeanmichel@sequans.com> - 2014-10-27 11:19 +0100

csiph-web