(Tkinter) Can I bind a key to Canvas?

D

Davy

Hi all,

I have a canvas and a rectangle draw on it. Can I bind a key(e.g. UP)
to the canvas and make the rectangle move up? Or shall I bind the key
to rectangle(I don't think so, because it is not a widget)?

Any suggestions are welcome!
Best regards,
Davy
 
D

Davy

I have tried key and mouse click (when receive a event, print some
diagnose information ). I found mouse click work well in canvas but
key not work well.

It seems canvas cannot get key event?

self.canv.bind('<Up>',self._onUpKey) ## don't work
self.canv.bind('<Button-1>', self._onClick) ## work

Any suggestion?

Best regards,
Davy
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top