TAB and Enter key in Tkinter

Discussion in 'Python' started by Scott Holmes, Aug 9, 2003.

  1. Scott Holmes

    Scott Holmes Guest

    I've noticed that widgets in a Pmw toplevel are navigated by tab key. I
    find I can tab between the entry fields and the buttons but hitting the
    enter key after moving to a button does not activate the button. If
    possible, how do I configure buttons to accept and enter key event?
    --
    ---------------------------------------------------------------------
    Scott Holmes http://sholmes.ws
    http://pages.sbcglobal.net/scottholmes


    Independent Programmer/Analyst Passport 4GL
    PHP HTML Composer PostgreSQL Informix 4GL, SQL
    ---------------------------------------------------------------------
    There are more things in heaven and earth, Horatio,
    than are dreamt of in your philosophy
    ---------------------------------------------------------------------
    Scott Holmes, Aug 9, 2003
    #1
    1. Advertising

  2. Scott Holmes

    klappnase Guest

    Scott Holmes <> wrote in message news:<>...
    > I've noticed that widgets in a Pmw toplevel are navigated by tab key. I
    > find I can tab between the entry fields and the buttons but hitting the
    > enter key after moving to a button does not activate the button. If
    > possible, how do I configure buttons to accept and enter key event?
    > --
    > ---------------------------------------------------------------------

    Hi,

    I suppose you probably bound the callback to your button with the
    "command=" option, like:

    button1 = Button(parent, text="Hello", command=some_function)

    In this case you will get the default Tk behavior that the callback is
    invoked with a (mouse-) Button-1 or a Space-Key press.
    If you do not want this, use the bind method instead like:

    button1 = Button(parent, text="Hello")
    button1.bind("<ButtonRelease-1>", some_function)
    button1.bind("<KeyRelease-Return>", some_function)

    This way you will get the behavior I think you want. Of course you can
    bind any other event to your callback this way.
    Please note that the "bind" method unlike the "command" option passes
    the event as (the first) argument to the callback function, so you
    will have to change the definition line like this:

    #callback for use with "command" option
    def some_function():
    do_something

    #callback for use with "bind" method
    def some_function(event):
    do_something

    I hope this helped.

    Best regards

    Michael
    klappnase, Aug 9, 2003
    #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. Karen Grube

    Urgent: How can I get the enter key to behave like a tab key?

    Karen Grube, Nov 28, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    289
    Karen Grube
    Nov 29, 2004
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    371
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    454
  4. max
    Replies:
    2
    Views:
    360
    Lambik
    Apr 1, 2007
  5. HopfZ
    Replies:
    0
    Views:
    276
    HopfZ
    Jan 8, 2007
Loading...

Share This Page