[Tutor] Keypress event in canvas..........
Python-lover
hemanexp@yahoo.com
Sat May 24 13:03:43 2003
--0-1924752861-1053795694=:29590
Content-Type: text/plain; charset=us-ascii
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.
--0-1924752861-1053795694=:29590
Content-Type: text/html; charset=us-ascii
<DIV>Hi,</DIV>
<DIV> 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?</DIV>
<DIV> </DIV>
<DIV> My sample code is given below:</DIV>
<DIV>***************************************</DIV>
<DIV>from Tkinter import *<BR>class App:<BR> def __init__(self,parent):<BR> self.myparent = parent<BR> self.canvas = Canvas(self.myparent,width=600,height=500)<BR> self.canvas.pack()<BR> x1 = 100<BR> y1 = 100<BR> x2 = 200<BR> y2 = 200<BR> i = 1<BR> while i<4:<BR> self.canvas.create_rectangle(x1,y1,x2,y2,tag='RECT',fill='red')<BR> y1 = y2<BR> y2 = y1 + 100<BR> i = i+1</DIV>
<DIV> self.canvas.tag_bind('RECT','<Up>', self.get_rect_points)</DIV>
<DIV> </DIV>
<DIV> def get_rect_points():<BR> #.......................<BR> # Here i want to get rectangle points<BR> #........................</DIV>
<DIV> <BR>root = Tk()<BR>myapp = App(root)<BR>root.mainloop()</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Thanx.</DIV>
<DIV> </DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
<a href="http://us.rd.yahoo.com/search/mailsig/*http://search.yahoo.com">The New Yahoo! Search</a> - Faster. Easier. Bingo.
--0-1924752861-1053795694=:29590--