Tkinter 이벤트는 위젯과 바인딩되어 위젯에서 일련의 작업을 수행할 수 있습니다. 더 구체적으로 말하면 bind(을 사용하여 이벤트 핸들러를 Canvas 항목에 바인딩할 수도 있습니다. 방법. 이벤트를 캔버스 항목과 바인딩하면 이벤트 핸들러로 사용자 정의할 수 있는 캔버스 항목을 동적으로 만듭니다.
예시
#Import the required Libraries
from tkinter import *
import random
#Create an instance of Tkinter frame
win = Tk()
#Set the geometry of the window
win.geometry("700x350")
#Crate a canvas
canvas=Canvas(win,width=700,height=350,bg='white')
def draw_shapes(e):
canvas.delete(ALL)
canvas.create_oval(random.randint(5,300),random.randint(1,300),25,25,fill='O rangeRed2')
canvas.pack()
#Bind the spacebar Key to a function
win.bind("<space>", draw_shapes)
win.mainloop()에 바인딩 출력
위의 코드를 실행하면 Canvas가 포함된 창이 표시됩니다.

