简体   繁体   中英

Delete text from Canvas, after some time (tkinter)

I need to remove text from canvas after some time.

y = cnv3.create_text(600, 430, text='Authentication failed', font=('Times', 30), fill='yellow')

I tried this:

time.sleep(2)
cnv3.pack_forget(y)

Result: It does not even appear the text.

And this:

root.after(2000, cnv3.delete(y))

Not working too.

Please help, I looked almost everywhere and I didn't find how to do that.

You have to give after a reference to a function. The way you're doing it is immediately calling the delete function and then passing the result of that to after .

It needs to look like this:

root.after(2000, cnv3.delete, y)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM