[Tkinter-discuss] Which virtual event have I received ?

Bryan Oakley bryan.oakley at gmail.com
Wed May 9 16:44:05 CEST 2012


On Wed, May 9, 2012 at 6:07 AM, hamiljf <john at 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>>"):
            ...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20120509/02701513/attachment.html>


More information about the Tkinter-discuss mailing list