Tkinter code (with pmw) executing to soon please help

Eric_Dexter at msn.com Eric_Dexter at msn.com
Sun Jan 14 02:40:23 EST 2007


> button[num] = Tkinter.Button(frame,text =  returnstring,
> command=callback(returnstring))#


I understand this part of it

def callback(text):
  def handler(event):
    print text

It stopped calling it automaticaly but will not do anything when I
click on the button.  Does something have to change on this line as
well.

button[num] = Tkinter.Button(frame,text =  returnstring,
> command=callback(returnstring)





Gabriel Genellina wrote:
> <Eric_Dexter at msn.com> escribió en el mensaje
> news:1168746063.322340.10410 at l53g2000cwa.googlegroups.com...
>
> > Instead of creating my buttons and waiting for me to press them to
> > execute they are executing when I create them and won't do my callback
> > when I press them..  thanks for any help in advance
>
> This is a very frequent beginner's mistake. You are *calling* the event
> handler at the moment you create the buttons. You have to provide a
> *callable* but not call it yet.
>
> > button[num] = Tkinter.Button(frame,text =  returnstring,
> > command=callback(returnstring))#
>
> So `callback` should return a function, like this:
>
> def callback(text):
>   def handler(event):
>     print text
> 
> -- 
> Gabriel Genellina




More information about the Python-list mailing list