Retrieving event descriptors in Tkinter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Avi Kak

    #1

    Retrieving event descriptors in Tkinter

    Does Tkinter provide a function that returns all the event descriptors
    for a given widget class? I am looking for something similar to what
    you get in Perl/Tk when you call bind() with a single explicit
    argument. For example, in Perl/Tk,

    $widget->bind( Tk::Button )

    returns a list like

    <Key-Return>
    <Key-space>
    <ButtonReleas e-1>
    ....

    Is it possible to do the same in Tkinter? I have looked through
    Fredrik Lundh's on-line reference and also the one by John Shipman. I
    am unable to locate the function I need. Perhaps I have not looked hard
    enough. Any help would be much appreciated.

    Thanks.

    Avi Kak
    kak@purdue.edu

  • Fredrik Lundh

    #2
    Re: Retrieving event descriptors in Tkinter

    Avi Kak wrote:
    [color=blue]
    > Does Tkinter provide a function that returns all the event descriptors
    > for a given widget class? I am looking for something similar to what
    > you get in Perl/Tk when you call bind() with a single explicit
    > argument. For example, in Perl/Tk,
    >
    > $widget->bind( Tk::Button )
    >
    > returns a list like
    >
    > <Key-Return>
    > <Key-space>
    > <ButtonReleas e-1>
    > ....
    >
    > Is it possible to do the same in Tkinter? I have looked through
    > Fredrik Lundh's on-line reference and also the one by John Shipman. I
    > am unable to locate the function I need. Perhaps I have not looked hard
    > enough. Any help would be much appreciated.[/color]

    Tkinter matches Tk quite closely, and there's no way to get *all* bindings
    for a standard widget with a single call at the Tk level (afaik).

    to extract the same information from a Tkinter widget, you should first call
    bindtags() on the widget to get a list of binding classes used for this widget,
    and you can then use bind_class(cls) to get the events for that class.

    to get all events, you can use something like:
    [color=blue][color=green][color=darkred]
    >>> bindings = set()
    >>> for cls in b.bindtags():[/color][/color][/color]
    .... bindings |= set(b.bind_clas s(cls))
    ....[color=blue][color=green][color=darkred]
    >>> bindings[/color][/color][/color]
    set(['<Alt-KeyRelease>', '<Leave>', '<Enter>', '<KeyRelease-Alt_L>',
    '<Key-Alt_R>', '<<PrevWindow>> ', '<Key-F10>', '<KeyRelease-F10>',
    '<Key-space>', '<Alt-Key>', '<Button-1>', '<ButtonReleas e-1>',
    '<KeyRelease-Alt_R>', '<Key-Tab>', '<Key-Alt_L>'])

    </F>



    Comment

    • Avi Kak

      #3
      Re: Retrieving event descriptors in Tkinter

      Thanks very much. That's exactly what I was looking for. --- Avi

      Comment

      Working...