Armido Maamägi Armido Maamägi - 6 months ago 32
Python Question

Python Tkinter picture display

from tkinter import *
import time
frame = Tk()
frame.title("Blackjack")
canvas = Canvas(frame, width=600, height=400)
canvas.grid()



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)
time.sleep(5)
canvas.delete(img)


frame.mainloop()


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

Answer

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))