0

I am writing some code to play poker, and when the cards are dealt I would like a small pause between each card being shown. I have seen other answers which suggest using sleep or after, however I find that these pause the program but then show the cards simultaneously. I would like a pause between each card. This is my code as slimmed down as I can put it.

from tkinter import *
import time

x = Tk()
x.state('zoomed')

def lay():
    card1.place(relx=0.2, rely=0.2) # here I want to put a short pause
    #time.sleep(1)  or x.after(1000)
    card2.place(relx=0.4, rely=0.2)    

card1 = 'ad.gif'
card2 = '4c.gif'

a = PhotoImage(file='ad.gif')
card2 = Label(x, image=a)
b = PhotoImage(file='4c.gif')
card1 = Label(x, image=b)

Button(x, text='LAY CARDS', command=lay).place(relx=0.5, rely=0.5)

x.mainloop
Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46

1 Answers1

0

You can use .after() to show card2 after one second:

def lay():
    card1.place(relx=0.2, rely=0.2)
    # show card2 one second later
    x.after(1000, lambda: card2.place(relx=0.4, rely=0.2))
acw1668
  • 40,144
  • 5
  • 22
  • 34