bindings in Tkinter

Discussion in 'Python' started by p.kosina, Jun 14, 2004.

  1. p.kosina

    p.kosina Guest

    I made a "notebook" script in Python and bind CTRL+N as next file. At
    the first time it works well, but then it stops. I found, that I have to
    release CTRL, when using this second time. Is there any solution so I do
    not have to release CTRL and just keep pressing N,N,N,....

    Thanks a lot
    Pavel

    Using Python 2.3 under W2k.
     
    p.kosina, Jun 14, 2004
    #1
    1. Advertising

  2. p.kosina

    Jeff Epler Guest

    The following program just fine for me, printing "Control-N"
    multiple times without the need to release and re-press control each
    time:
    from Tkinter import Tk
    t = Tk()
    def puts(s): print s
    t.bind("<Key-Control_L>", lambda e: puts("Control"))
    t.bind("<Key-Control_R>", lambda e: puts("Control"))
    t.bind("<KeyRelease-Control_L>", lambda e: puts("Released Control"))
    t.bind("<KeyRelease-Control_R>", lambda e: puts("Released Control"))
    t.bind("<Control-n>", lambda e: puts("Control-N"))
    t.mainloop()

    Your problem must be because you've done something more complicated than
    you've told us. For instance, if your binding for <Control-n> creates
    or destroys widgets, moves the input focus, etc., maybe something bad is
    happening.

    Jeff

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.1 (GNU/Linux)

    iD8DBQFAzam6Jd01MZaTXX0RAp6uAJ9iGCEk6rcOv7OWJip71CkEZg7JoACgrMwp
    fHtcrQazgmh+2UNTsmMPvxk=
    =IkkD
    -----END PGP SIGNATURE-----
     
    Jeff Epler, Jun 14, 2004
    #2
    1. Advertising

  3. p.kosina

    p.kosina Guest

    Solved.- I must have old documentation, I used '<Control_L>n'.
    Thank you.
    Pavel



    Jeff Epler napsal(a):
    > The following program just fine for me, printing "Control-N"
    > multiple times without the need to release and re-press control each
    > time:
    > from Tkinter import Tk
    > t = Tk()
    > def puts(s): print s
    > t.bind("<Key-Control_L>", lambda e: puts("Control"))
    > t.bind("<Key-Control_R>", lambda e: puts("Control"))
    > t.bind("<KeyRelease-Control_L>", lambda e: puts("Released Control"))
    > t.bind("<KeyRelease-Control_R>", lambda e: puts("Released Control"))
    > t.bind("<Control-n>", lambda e: puts("Control-N"))
    > t.mainloop()
    >
    > Your problem must be because you've done something more complicated than
    > you've told us. For instance, if your binding for <Control-n> creates
    > or destroys widgets, moves the input focus, etc., maybe something bad is
    > happening.
    >
    > Jeff
     
    p.kosina, Jun 16, 2004
    #3
  4. p.kosina

    Jeff Epler Guest

    On Wed, Jun 16, 2004 at 06:58:37AM +0200, p.kosina wrote:
    > Solved.- I must have old documentation, I used '<Control_L>n'.
    > Thank you.
    > Pavel


    Aha!

    The first argument to bind can be a sequence of events, which would
    explain exactly the behavior you saw. This *can* be useful (it's in
    effect how double-click works) but it can also do something different
    than what you want.

    Jeff

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.1 (GNU/Linux)

    iD8DBQFA0D48Jd01MZaTXX0RAsX7AKCpc4kDteZdymyEjOGuTU8Y5FbITACcCjj7
    xXvwMsGBYpBc60Id5PGuutE=
    =kOTv
    -----END PGP SIGNATURE-----
     
    Jeff Epler, Jun 16, 2004
    #4
    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. Will Woods

    Tkinter and readline key bindings

    Will Woods, Sep 2, 2003, in forum: Python
    Replies:
    0
    Views:
    386
    Will Woods
    Sep 2, 2003
  2. Phil Schmidt

    Tkinter default bindings

    Phil Schmidt, Mar 1, 2004, in forum: Python
    Replies:
    1
    Views:
    406
    Martin Franklin
    Mar 2, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    527
    Jeff Epler
    Aug 20, 2004
  4. Jeff Epler
    Replies:
    0
    Views:
    475
    Jeff Epler
    Aug 23, 2004
  5. Roger
    Replies:
    7
    Views:
    718
    Roger
    Jan 13, 2009
Loading...

Share This Page