Skip to content
Advertisement

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.

Advertisement

Answer

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)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement