Newbie alert !
Lonnie Princehouse
finite.automaton at gmail.com
Fri Dec 3 13:10:24 EST 2004
> bou_asia=Button(fen1, text='Asia',\
> command=rings(size=41, offsetX=50,offsetY=22,
> coul='yellow'))
You're calling the rings function when you create the button.
What you really want is for "command" to be a callable object
that the button will invoke when it's clicked, e.g.:
def mycallback():
print 'click'
mybutton = Button(parent, text='a button', command = mycallback)
Notice that there are no parentheses after mycallback -- it's not
being called, but the function itself is being passed as an argument.
In your case, you need to find a way to pass arguments to rings, so
you'll have to curry the function. Here's one way to do it:
def rings_callback(**keywords):
# return an anonymous function that calls rings when invoked.
return lambda k=keywords: rings(**k)
bou_asia = Button(fen1, text='Asia',
command=rings_callback(size=41, offsetX=50,offsetY=22,
coul='yellow'))
Hope that helps.
More information about the Python-list
mailing list