Re: [Tutor] Tkinter-Button class

2007-03-19 Thread Kent Johnson
ammar azif wrote:
> Hi,
> 
> Thanks for answering .. btw what do you mean by explicit , helper 
> function? Can you explain about these functions?

I just mean, define an ordinary function of no arguments that does what 
you want. For example, the calculator program I linked to has this Button:
tk.Button(root,text='1',width=5,relief=tk.RIDGE,
   command=lambda: click('1'))

That could be written as
def click1():
   click('1')
tk.Button(root,text='1',width=5,relief=tk.RIDGE, command=click1)

Notice there are no parentheses after 'click1' in the Button definition; 
you are passing the actual function to the Button.

Kent

PS Please reply on-list.

> 
> */Kent Johnson <[EMAIL PROTECTED]>/* wrote:
> 
> ammar azif wrote:
>  > Hi,
>  >
>  > Thanks for the help guys.
>  >
>  >
>  > I have tried gui programming using Tkinter and use the Button class
>  > which accepts the command argument which is a function object.
>  >
>  > The question is how to send arguments if the function accepts
> arguments.
> 
> A common way to do this is to use a lambda expression to bind the
> arguments, e.g.
> Button(..., command = lambda: func_with_args(1, 2, 3))
> 
> For example see
> http://www.daniweb.com/code/snippet610.html
> 
> You could also define explicit, short helper functions if you don't
> want
> to use lambdas.
> 
> Kent
> 
> 
> 
> Don't pick lemons.
> See all the new 2007 cars 
> 
>  
> at Yahoo! Autos. 
> 
>  
> 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tkinter-Button class

2007-03-19 Thread Kent Johnson
ammar azif wrote:
> Hi,
> 
> Thanks for the help guys.
> 
> 
> I have tried gui programming using Tkinter and use the Button class 
> which accepts the command argument which is a function object.
> 
> The question is how to send arguments if the function accepts arguments.

A common way to do this is to use a lambda expression to bind the 
arguments, e.g.
Button(..., command = lambda: func_with_args(1, 2, 3))

For example see
http://www.daniweb.com/code/snippet610.html

You could also define explicit, short helper functions if you don't want 
to use lambdas.

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Tkinter-Button class

2007-03-18 Thread ammar azif
Hi,

Thanks for the help guys.


I have tried gui programming using Tkinter and use the Button class which 
accepts the command argument which is a function object.

The question is how to send arguments if the function accepts arguments.





 
-
 Get your own web address.
 Have a HUGE year through Yahoo! Small Business.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor