Where are Tkinter event.type constants defined?

Discussion in 'Python' started by Noah, May 5, 2008.

  1. Noah

    Noah Guest

    I'm trying to match against Event.type for KeyPress and ButtonPress.
    Currently I'm using integer constants (2 and 4). Are these constants
    defined anywhere? The docs talk about KeyPress and ButtonPress, but I
    don't see them in any of the Tkinter source files. Are these just
    magic values that come out of the TK side of things and are not
    defined in Python? Code like this makes me think I'm doing something
    wrong:

    if event.type == 2:
    handle_key_press (event.char)
    elif event.type == 4:
    do_something_for_button ()
    else:
    pass # unknown event

    (I understand that usually you would bind these function so that they
    are called as a callback.)

    I don't mind defining the constants myself. I just want to make sure
    that I'm not missing something already done for me. Does anyone happen
    to have a complete list of Event.type constants?

    --
    Noah
    Noah, May 5, 2008
    #1
    1. Advertising

  2. On May 4, 7:22 pm, Noah <> wrote:
    > I'm trying to match against Event.type for KeyPress and ButtonPress.
    > Currently I'm using integer constants (2 and 4). Are these constants
    > defined anywhere? The docs talk about KeyPress and ButtonPress, but I
    > don't see them in any of the Tkinter source files. Are these just
    > magic values that come out of the TK side of things and are not
    > defined in Python? Code like this makes me think I'm doing something
    > wrong:
    >
    >     if event.type == 2:
    >         handle_key_press (event.char)
    >     elif event.type == 4:
    >         do_something_for_button ()
    >     else:
    >         pass # unknown event
    >
    > (I understand that usually you would bind these function so that they
    > are called as a callback.)
    >
    > I don't mind defining the constants myself. I just want to make sure
    > that I'm not missing something already done for me. Does anyone happen
    > to have a complete list of Event.type constants?
    >
    > --
    > Noah


    Hey Noah,

    I recommend checking out Lundh's site (effbot) since he has lots of
    information on Tkinter there. Here's his Tkinter event page:

    http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

    And there's this (less helpful):

    http://docs.python.org/lib/node699.html

    There's a whole chapter on events Grayson's Tkinter book, but I'm not
    seeing constants defined. I think they might vary somewhat across
    platforms anyway...but hopefully someone else more knowledgeable will
    come along and address that.

    Mike
    Mike Driscoll, May 5, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    463
  2. Dave Harris

    Type constants in type module

    Dave Harris, Nov 2, 2003, in forum: Python
    Replies:
    1
    Views:
    266
    Terry Reedy
    Nov 2, 2003
  3. Oodini
    Replies:
    1
    Views:
    1,750
    Keith Thompson
    Sep 27, 2005
  4. J.W

    Compare to a defined constants in C?

    J.W, Dec 26, 2010, in forum: C Programming
    Replies:
    10
    Views:
    885
    Keith Thompson
    Dec 28, 2010
  5. Paul Brannan
    Replies:
    13
    Views:
    282
    Paul Brannan
    Mar 4, 2008
Loading...

Share This Page