[Pythonmac-SIG] Buttons in W
François Granger
francois.granger@free.fr
Fri, 23 Mar 2001 20:05:18 +0100
At 19:47 +0100 23/03/01, in message Re: [Pythonmac-SIG] Buttons in W,
Just van Rossum wrote:
Thanks for fast answer.
>
>My usual trick is to work with default arguments. Ugly, but works. Small
>example:
>
>import W
>
>w = W.Window((400, 400), "Test")
>
>for i in range(5):
> def callback(buttonNumber=i):
> print "button", buttonNumber, "was pressed"
> w[i] = W.Button((10, 10 + 24 * i, 60, 18),
> "Button #%s" % i, callback)
>w.open()
I thought of this. I did not tested it because it was sayd that the
call back was called with no argument. And I did not though further
;-)
>PS: the w attrs starting with an underscore are sortof private: you should
>try to avoid using them.
Yes, I know, but that is because I don't yet know "the right thing to do".
For exemple, I need to be able to change the button name after
creation. How do I do ?
--
"Faites des phrases courtes. Un sujet, un verbe, un complément. Quand
vous voudrez ajouter un adjectif, vous viendrez me voir." - Georges
Clemenceau, 1841-1929, médecin et homme politique français. Consignes
aux journalistes de "L'Aurore". d'après
<http://www.sit.ulaval.ca/pagespersonnelles/phf/pensee.html>