python tkinter canvas when rectangle clicked
问题 I've been trying to make a function run when I click a rectangle on a tk canvas. Here is the code: from tkinter import * window = Tk() c = Canvas(window, width=300, height=300) def clear(): canvas.delete(ALL) playbutton = c.create_rectangle(75, 25, 225, 75, fill="red") playtext = c.create_text(150, 50, text="Play", font=("Papyrus", 26), fill='blue') c.pack() window.mainloop() does anyone know what I should do? 回答1: You can add tags on the items you want to bind events to. The event you want