Bonjour,

Je créer un programme assez simple permettant d'afficher un nombre de voir si quelque seconde après la disparition de ce nombre il s'en souvient.
Je veux donc créer un compteur qui indique à l'utilisateur combien de temps il lui reste avant que le nombre ne soit caché.



Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from tkinter import *
import time
 
#main
fenetre_jeu = Tk()
fenetre_jeu.wm_state(newstate="zoomed")
fenetre_jeu.title("Lesson sympa")
fenetre_jeu['bg'] = "light sky blue"
 
##########################################################
def jeu_lance():
    liste_chrono = ['3', '2', '1']
    for x in range(3):
        label_compteur.config(text = liste_chrono[x]) 
        time.sleep(1)
 
def lancement_page():
    bouton_play.pack_forget()
    # label_nombre_aleatoire
    label_nombre_aleatoire = Label(frame_central, bg = 'yellow', fg = 'blue', font = ('Impact', 20), width = 20, justify = CENTER)
    label_nombre_aleatoire.grid(row = 0, column = 1)
    #label compteur
    global label_compteur
    label_compteur = Label(frame_central, bg = "light sky blue", fg = 'red', font = ('Impact', 20), text = "3", width = 2)
    label_compteur.grid(row = 0, column = 2)
    #label placement
    label_placement = Label(frame_central, bg = "light sky blue", font = ('Impact', 20), width = 2)
    label_placement.grid(row = 0, column = 0)
    jeu_lance()
###########################################################
 
# frame central
global frame_central
frame_central = Frame(fenetre_jeu, borderwidth = 1, bg="light sky blue")
frame_central.pack(expand = YES)
#bouton play
global bouton_play
bouton_play = Button(frame_central, bg = 'red', fg = 'blue', font = ('Arial', 20), text = 'PLAY', command = lancement_page)
bouton_play.pack()


Malheureusement, l'execution ne se fait qu'au bout de la boucle for. Donc Le 1 apparait mais pas les autres chiffres.
J'ai decouvert .after() mais ça me parait compliqué à utiliser. Y a t il un meilleur moyen de le faire ou sinon comment puis je l'utiliser.