Keypress event in canvas..........
Python-lover
hemanexp at yahoo.com
Sat May 24 13:01:34 EDT 2003
Hi, iam using python and Tkinter. Is it possible to bind a keyboard event, say "Up" arrow press, to a canvas item (like rectangle)? i have created a canvas and drawn a set of rectangles one above another.Now when i press "Up" arrow key first time i expect first rectangle to get focus and second one for next keypress and so on utill you reach the last rectangle. how can i do it? My sample code is given below:***************************************from Tkinter import *
class App:
def __init__(self,parent):
self.myparent = parent
self.canvas = Canvas(self.myparent,width=600,height=500)
self.canvas.pack()
x1 = 100
y1 = 100
x2 = 200
y2 = 200
i = 1
while i<4:
self.canvas.create_rectangle(x1,y1,x2,y2,tag='RECT',fill='red')
y1 = y2
y2 = y1 + 100
i = i+1 self.canvas.tag_bind('RECT','<Up>', self.get_rect_points) def get_rect_points():
#.......................
# Here i want to get rectangle points
#........................
root = Tk()
myapp = App(root)
root.mainloop() Thanx.
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030524/21e6dd41/attachment.html>
More information about the Python-list
mailing list