On Wed, May 9, 2012 at 6:07 AM, hamiljf <j...@hamilton.org.uk> wrote:

> I want to be able to process more than one event type in an event handler
> (I
> know that there may be other ways of doing this, and I might well use them)
> Now 'real' events are distinguished by event.type having a numeric value
> listed all over the place, for example in
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/events.html new mexico tech
> dox , and I think virtualevents are #35 (not in the list).  But how can I
> tell which of two virtual events an event object represents: the virtual
> event name doesn't seem to be anywhere around.  If there really isn't any
> way, it would always be possible to write additional handler methods as an
> alternative.
>

One simple solution is for your binding to pass the event type into your
callback. For example:

        widget.bind("<<CustomOne>>",
            lambda event, virtual="<<CustomOne>>": self.on_virtual(virtual,
event))
        widget.bind("<<CustomTwo>>",
            lambda event, virtual="<<CustomTwo>>": self.on_virtual(virtual,
event))
        ...
    def on_virtual(self, virtual, event):
        if (virtual == "<<CustomOne>>"):
            ...
_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss@python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss

Reply via email to