如何使用tkinter删除行

如何使用tkinter删除行,tkinter,Tkinter,我正在用tkinter用python编写一个程序,我需要一个canvas对象在一秒钟后删除,但我不知道要使用什么函数,我找不到它。这是我的代码: def click(event): canvas.create_line(event.x, event.y, coords) canvas.after(1000,canvas.delete) canvas.bind('<B1-Motion>',click) def单击(事件): canvas.create_行(event

我正在用tkinter用python编写一个程序,我需要一个canvas对象在一秒钟后删除,但我不知道要使用什么函数,我找不到它。这是我的代码:

def click(event):
    canvas.create_line(event.x, event.y, coords)
    canvas.after(1000,canvas.delete)

canvas.bind('<B1-Motion>',click)
def单击(事件):
canvas.create_行(event.x、event.y、coords)
canvas.after(1000,canvas.delete)
canvas.bind(“”,单击)

当我打电话给你的时候,电话就停在那里

在画布上创建项目时,tkinter将返回唯一标识符。只需保存标识符,并将其用作
canvas.delete的参数

def click(event):
    canvas_id = canvas.create_line(event.x, event.y, coords)
    canvas.after(1000, canvas.delete, canvas_id)
简单地
canvas.delete(变量)
如下:

from tkinter import *
from tkinter import Canvas
app = Tk()

canvas = Canvas(Screen, width=800, height=400)
canvas.pack()

Boom = canvas.create_line(200, 10, 200, 500)

Button(text="Click to del the line",font=("arial",10),bg="black",command=del_line).pack()

def del_line():
    canvas.delete(Boom)

app.mainloop()
就这样