Info passed thru 'Event' 
Author Message
 Info passed thru 'Event'

I need to have information in my callback functions that is specific to
the widget that called it. What information (and how can I access it) is
passed through the 'event' parameter (especially its 'widget' attr.)

If this information is different for different widgets, where can I find
more information about each widget's 'Event'

Can I pass parameters to the callback function?

thanks
edi bice



Fri, 05 Jan 2001 03:00:00 GMT  
 Info passed thru 'Event'

Quote:

> Can I pass parameters to the callback function?

It sounds like you are using top-level functions for your callbacks.
Personally, I prefer to use class methods; a separate method for each
widget.  A simple example:

class MyApp(Frame):
  def __init__(self, master, message):
    Frame.__init__(self, master)
    self.b = Button(self, text="Push me", command=self.pushme_callback)
    self.b.pack()

  def pushme_callback(self, *ignored_args):
    # do whatever

You can access instance data through the self parameter.

Milton L. Hankins   <><   Software Engineer, Raytheon Systems Company
 John 3:16 || I can't speak for Raytheon Company, but I often try to
  L-I-F-E  || speak for my wife and my cat.  The latter doesn't mind.



Sun, 07 Jan 2001 03:00:00 GMT  
 Info passed thru 'Event'

Quote:
>I need to have information in my callback functions that is specific to
>the widget that called it. What information (and how can I access it) is
>passed through the 'event' parameter (especially its 'widget' attr.)

>If this information is different for different widgets, where can I find
>more information about each widget's 'Event'

Here's a summary:

char: character (empty (KeyPress, KeyRelease)
focus: focus state (Enter, Leave)
height: widget height (Configure, Expose)
keycode: the keyboard keycode (KeyPress, KeyRelease)
keysym: the keyboard keysym (KeyPress, KeyRelease)
keysym_num: the keyboard keysum, as a number (KeyPress, KeyRelease)
num: the button number (ButtonPress, ButtonRelease)
serial: a unique serial number for this event
state: additional event information (Visibility)
time: timestamp
type: event type
widget: the widget instance generating this event
width: widget width (Configure, Expose)
x: window-relative mouse x position (mouse events)
x_root: screen-relative mouse x position (mouse events)
y: window-relative mouse y position (mouse events)
y_root: screen-relative mouse y position (mouse events)

For portability reasons, you should stick to "char", "height", "width",
"x", "y", "x_root", "y_root", and "widget" unless you know exactly what
you're doing...

also see:
http://www.pythonware.com/library/tkinter/introduction/intro06.htm

Quote:
>Can I pass parameters to the callback function?

yes.  the easiest way is to use lambda wrappers:

    b1 = Button(master, text="One", command=lambda: click(1))
    b2 = Button(master, text="Two", command=lambda: click(2))
    b3 = Button(master, text="Three", command=lambda: click(3))

    b1.bind("<Button-3>", lambda e: rightclick(1))

Note that to give th lambda statement access to members from your
local namespace, you need to explicitly pass them to the statement
as default arguments:

    for i in range(10):
        b = Button(master, text=str(i), command=lambda v=i: click(v))
        b.pack()

Cheers /F

http://www.pythonware.com



Mon, 08 Jan 2001 03:00:00 GMT  
 Info passed thru 'Event'
Which reminds me...

I've written a simple Tkinter app that uses a handler for <Configure>
to detect when the user resizes a toplevel window, but the app also
resizes the window itself at times.  On Windows (at least) this is
very painful to get right -- to the point where I've disabled the
behavior.  The problem is that Tk generates <Configure> events for a
number of reasons, including resizes that program-initiated resizes,
and focus changes.  To make things worse, I can't always predict how
big the window will be as a result of a program-initiated resize,
because of various borders, a minimum size set by the title, etc.

Has anybody else struggled with this and found a solution?  (I could
put a timer in to ignore resizes within a few seconds of
program-initiated resizes, but that's a gross hack, and doesn't always
work -- when the system is busy the delays can become arbitrarily
long.)

An alternative would be a way to designate a corner of the window
(e.g. a 20x20 pixel area in the bottom-right corner) as a resize
handle.  Would there be a way to do this but let the system handle the
resize?  (Windows can clearly do this -- but how to get Tk to do
this...)

--Guido van Rossum (home page: http://www.python.org/~guido/)



Mon, 08 Jan 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Info passed thru 'Event'

2. Expect event loop triggers 'after' events

3. Info on Tcl's channel system (specifically file events) needed

4. Boolean controls don't respond to input when inside an event in the event structure

5. Merging Tcl's event loop with some other event loop

6. Merging Tcl's event loop with other event loops (notifier)

7. I need 'EVENT:Paint'

8. VI's GUI events disturb another VI's work

9. s'ACTIVE vs s'EVENT??

10. S'STABLE = not S'EVENT ?

11. HowTo use 'event gen'

12. tcl event loop + c code 'select'

 

 
Powered by phpBB® Forum Software