I would like to ask if it is possible in Python to delete a canvas object which was created with method.
My example code:
import tkinter
window = tkinter.Tk()
canvas = tkinter.Canvas(width=1000, height=600, bg="black")
canvas.pack()
def draw_yellow(x1, y1, x2, y2):
canvas.create_line(x1, y1, x2, y2, fill="yellow")
def draw_white(x1, y1, x2, y2):
canvas.create_line(x1, y1, x2, y2, fill="white")
line1 = draw_yellow(20, 300, 100, 300)
line2 = draw_white(20, 300, 100, 300)
line3 = draw_white(40, 200, 60, 200)
canvas.delete(line2)
However canvas.delete(line2) doesn't work with this way of creating canvas objects.
Is it somehow possible to draw and also delete objects drawn using functions? Thank you for the answers.