from tkinter import *
class Appliction(Frame):
def __init__(self,master=None):
super().__init__(master)
self.master=master
self.pack()
self.createwidget()
def createwidget(self):
self.canvas=Canvas(self,width=180,height=180,bg='gray')
self.canvas.pack()
self.canvas.bind('<1>',self.mousetest)
self.canvas.bind('<B1-Motion>',self.testdrag)
self.canvas.bind('<KeyPress>',self.keyboardtest)
def mousetest(self,event):
print('ab_place:{0},{1}'.format(event.x,event.y))
print('re_place:{0},{1}'.format(event.x_root,event.y_root))
def testdrag(self,event):
self.canvas.create_oval(int(event.x),int(event.y),int(event.x+1),int(event.y+1))
def keyboardtest(self,event):
print("char: {0},keycode: {1},keysym: {2}".format(event.char,event.keycode,event.keysym))
if __name__=='__main__':
root=Tk()
root.geometry("200x200")
root.title('event')
app=Appliction(master=root)
root.mainloop()
这边<KeyPress>对canvas绑定按键盘没有响应,是需要绑定root吗,在面向对象中怎么绑定root呢