Leero11 Leero11 - 1 year ago 111
Python Question

Python/Tkinter - delete all objects in enclosed area

I am trying to make a program where on click the program would delete all objects in enclosed area.

Here is my example code:

import tkinter as tk

root = tk.Tk()

cv = tk.Canvas(root, height=400, width=400)

cv.create_rectangle(50, 50, 100, 100)

cv.create_line(60, 60, 80, 80)

cv.create_line(60, 80, 80, 60)

def onclick():

todel = cv.find_enclosed(50, 50, 100, 100)

cv.bind("<Button-1>", onclick())


On click it should delete the two lines in the rectangle, but for some reason it does not. How can I make this happen?

Answer Source

You have to apply delete to all items of the list

for d in todel:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download