Armido Maamägi Armido Maamägi - 2 years ago 199
Python Question

Python Tkinter picture display

from tkinter import *
import time
frame = Tk()
canvas = Canvas(frame, width=600, height=400)

background = PhotoImage(file="taust.gif")
card1 = PhotoImage(file="kaart1.gif")
img = canvas.create_image(300, 200, image=background)
img2 = canvas.create_image(300, 300, image=card1)


I want to display both pictures and after 5 seconds I want to delete one picture and keep the other.

Answer Source

Get rid of the time.sleep and just use frame.after.

The after method - after(delay in ms, callback, *arguments)

So, we can use frame.after(5000, lambda: canvas.delete(img))

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download