By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,517 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,517 IT Pros & Developers. It's quick & easy.

Tkinter Event Types

P: n/a
Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like...

def callback(self, event):
if event.type == ENTER:
print "You entered"

thanks

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
codecraig wrote:
Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like... 7 must be for KeyPressed.
That's the type of the event (among Activate, Button, KeyPressed...).

def callback(self, event):
if event.type == ENTER:
print "You entered"


You may want to look at event.keycode (36 for Return).

Jul 19 '05 #2

P: n/a
The "type" field is related to the definition of different events in
X11. In Xlib, the event structure is a "C" union with the first
(common) field giving the type of the event so that the event-dependant
fields can be accessed through the proper union member.

Generally, you won't use this field in Tkinter programs.

jeff

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

iD8DBQFCZFtQJd01MZaTXX0RAmffAJwPXtWUugiSVGukuqc27M ZWcrs2zACfZfH7
PRNDFDXbj+DH9Df2xQywnWg=
=2ryT
-----END PGP SIGNATURE-----

Jul 19 '05 #3

P: n/a
On 18 Apr 2005 13:48:50 -0700, codecraig <co*******@gmail.com> wrote:
Hi,
When I do something like.

s = Scale(master)
s.bind("<ENTER>", callback)

def callback(self, event):
print event.type

I see "7" printed out. Where are these constants defined for various
event types? Basically i want to do something like...

def callback(self, event):
if event.type == ENTER:
print "You entered"


The usual way is to bind different callbacks on different events. So you won't have to test the event type in your callback, since the callback itself will already have been selected from the event type. If you insist in doing it the way you mention, you can always do:
ENTER_EVENT = 1
KEYPRESS_EVENT = 2
# ...

def myCallback(evtType, evt):
if evtType == ENTER_EVENT:
# some action...
elif evtType == KEYPRESS_EVENT:
# some other action...
# ...

myWidget.bind('<Enter>', lambda evt: myCallback(ENTER_EVENT, evt))
myWidget.bind('<KeyPress>', lambda evt: myCallback(KEYPRESS_EVENT, evt))
I can't really see what it will be good for however...

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.