0

so i'm doing a project for school with tkinter what i'm currently trying to do is display an image that is a 450x450px .gif

what it needs to do is open > 20sec delay > close

here is the current code

    photo = tkinter.PhotoImage(file = './Images/img1.gif')
    root.geometry("450x450")
    root.update()
    canvas.create_image(225,225, image=photo)
    root.mainloop()

https://i.stack.imgur.com/PSCce.png is the current result

Photonium
  • 7
  • 2
  • 7

1 Answers1

1

Save the return value of the create_image (item id), then use that value when you delete the image using canvas.delete.

photo = tkinter.PhotoImage(file = './Images/img1.gif')
root.geometry("450x450")
root.update()
img = canvas.create_image(225,225, image=photo)
root.after(20000, lambda: canvas.delete(img)) # 20,000 milli seconds = 20 seconds
root.mainloop()

Using after, you can do some stuff after specified time.

falsetru
  • 357,413
  • 63
  • 732
  • 636