[Tutor] Event Handling--Key Press, Mouse Movement ...

Gregor Lingl gregor.lingl at aon.at
Mon Apr 13 20:22:03 CEST 2009



Wayne Watson schrieb:
> Sometime ago, one of my posts brought a response brief exchange on 
> event handling*. Where might I find more about event handling with 
> respect to the keyboard, and particularly with a mouse. In the latter 
> case, I'm interested in finding the pixel position of the mouse on a 
> canvas.
>
Hi Wayne,

there is some (limited) support of event handling in the turtle module 
of Python 2.6
Example:

 >>> from turtle import *
 >>> reset()
 >>> def printpos(x,y):
        print x,y

   
 >>> onscreenclick(printpos)
 >>> -284.0 80.0    # result of clicking

the turtle module's playground is a Tkinter Canvas.
Don't know if that fit's to your needs in some way.

The module runs as is also with Python 2.5 and yuo can download
it separately from here:

http://svn.python.org/view/python/trunk/Lib/lib-tk/

More information on:

http://docs.python.org/library/turtle.html#module-turtle

Examples are in the source distribution (along with a demoViewer program,
which also serves as an example on how to embed turtle graphics into a
Tkinter application. You can download it separately from here:

http://svn.python.org/view/python/trunk/Demo/turtle/

If you have enough time and if you are interested in it, here is a PyCon 
talk
on the turtle module, which - as 6th "way" - contains a section on event 
driven
programs followed by two examples of games:

http://blip.tv/file/1947495

Best regards,
Gregor

> * I see from Alan Gauld, which refers to his web site. Still I'm 
> curious about other sources. The few books I have on Python seem to 
> avoid the subject. Perhaps it goes by another name in Python-ville.
>


More information about the Tutor mailing list