bindings in Tkinter

P

p.kosina

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.
 
J

Jeff Epler

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-----
 
P

p.kosina

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



Jeff Epler napsal(a):
 
J

Jeff Epler

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-----
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top