I am trying to create a game of luck where you have to pick 2 balls of the same color behind 3 doors and you 3 attempt, each doors have 1 ball and i'm blocked at the point where you open one door and i want to make a delay between the moment the door show the balls and the moment the balls disappear. I already tried with a time.sleep
but it runs the sleep at the time with the display. Here is my code:
import tkinter as tk
import tkinter as tk
from random import shuffle
import time
fenetre = tk.Tk()
fenetre['bg']='black'
fenetre.geometry("1152x768")
color = ["red", "green", "yellow"]
shuffle(color)
frameGauche = tk.Frame(width=200, height=600, bg='pink')
frameGauche.grid(row=0, column=0, padx=10, pady=10)
frameDroite = tk.Frame(width=700, height=700, bg='grey')
frameDroite.grid(row=0, column=1, padx=10, pady=10)
portegauche=tk.Frame(frameDroite, width=200,
height=600,bg='white',bd=5,relief='groove')
portegauche.grid(row=0, column=0, padx=5, pady=5)
portemilieu=tk.Frame(frameDroite, width=200,
height=600,bg='white',bd=5,relief='groove')
portemilieu.grid(row=0, column=1, padx=5, pady=5)
portedroite=tk.Frame(frameDroite, width=200,
height=600,bg='white',bd=5,relief='groove')
portedroite.grid(row=0, column=2, padx=5, pady=5)
def show1(canvas1, bouton2, bouton3):
canvas1.grid(row=0, column=1)
bouton2['state']='disabled'
bouton3['state']='disabled'
time.sleep(2)
bouton2['state']='normal'
bouton3['state']='normal'
canvas1.grid_remove()
def show2():
canvas2.grid(row=0, column=2)
bouton1['state']='disabled'
bouton3['state']='disabled'
time.sleep(2)
bouton1['state']='normal'
bouton3['state']='normal'
canvas2.grid_remove()
def show3():
canvas3.grid(row=0, column=3)
bouton2['state']='disabled'
bouton1['state']='disabled'
time.sleep(2)
bouton2['state']='normal'
bouton1['state']='normal'
canvas3.grid_remove()
canvas1=tk.Canvas(portegauche,width=200, height=600, bg='white')
c1 = canvas1.create_oval((60,280), (140,340), width=1, outline="black",
fill=color[0])
canvas1.grid_forget()
canvas2=tk.Canvas(portemilieu,width=200, height=600, bg='white')
c2 = canvas2.create_oval((60,280), (140,340), width=1, outline="black",
fill=color[1])
canvas2.grid_forget()
canvas3=tk.Canvas(portedroite,width=200, height=600, bg='white')
c3 = canvas3.create_oval((60,280), (140,340), width=1, outline="black",
fill=color[2])
canvas3.grid_forget()
def recommencer():
canvas1.grid_remove()
canvas2.grid_remove()
canvas3.grid_remove()
shuffle(color)
canvas1.create_oval((60,280), (140,340), width=1, outline="black", fill=color[0])
canvas2.create_oval((60,280), (140,340), width=1, outline="black", fill=color[1])
canvas3.create_oval((60,280), (140,340), width=1, outline="black", fill=color[2])
bouton1['state']='normal'
bouton2['state']='normal'
bouton3['state']='normal'
boutonR = tk.Button(frameGauche, text='Recommencer',command=recommencer)
boutonR.grid(row=0, column=0, padx=50, pady=50)
bouton1=tk.Button(frameDroite, text= 'Ouvrir',command=lambda: show1(canvas1,
bouton2, bouton3))
bouton1.grid(row=1, column=0)
bouton2=tk.Button(frameDroite, text= 'Ouvrir',command=show2)
bouton2.grid(row=1, column=1)
bouton3=tk.Button(frameDroite, text= 'Ouvrir',command=show3)
bouton3.grid(row=1, column=2)
fenetre.mainloop()