[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Newbie Tkinter Question
From:       John Grayson <johngrayson () home ! com>
Date:       2000-05-31 22:54:05
[Download RAW message or body]

Sure you can, just use a lambda expression. Here is
an example which shows an 'activate' callback (button
command) and a MB1 binding. Note that the binding 
has to allow for the event object:

from Tkinter import *

def prtIt(text):
    print text

root = Tk()

Button(root, text='B1', 
       command=lambda arg='Button 1': prtIt(arg)).pack(side=LEFT)

b2 = Button(root, text='B2')
b2.pack(side=LEFT)
b2.bind('<Button-1>', lambda e,arg='Button 2': prtIt(arg))

root.mainloop()

   John Grayson

Dean wrote:
> 
> Is it possible to pass arguments to a callback in Python/Tkinter?  I know
> this can be done in Perl, but after reviewing the documentation, it's not
> clear to me that you can pass any arguments ( except the event object ) to a
> callback function bound to an event.  Any help would be greatly appreciated!
> 
> Dean
-- 
http://www.python.org/mailman/listinfo/python-list

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic