Items de List pas possibilité affichage séquentiel dans un Label
Bonjour,
J'essaie d'afficher les items d'une List dans un Label de façon séquentiel avec un Bouton mais seul l'item[0] s'affiche et je ne vais pas plus loin.
J'ai utilisé un exemple simple, mais je ne comprend pourquoi la liste ne s'incrémente pas dans le Label, je suis sûr qu'il ya juste un détail qui m'a échappé, mais quoi ?
Je mets ce petit programme en suivant,
Merci pour votre aide
Jeangil
Code:
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
| import tkinter as tk
global words
index = -1
words = ["truc", "bidule", "machin", "chose", "ballon", "voiture", "chat", "maison",
"velo", "moto", "table"]
def on_click(display):
global index
index = index + 1
if (index >= len(words)):
index = 0
display.config(text=(words[index]))
#------------------------------------------------------------------
#main window
#------------------------------------------------------------------
root=tk.Tk()
label1 = tk.Label(text=(words[index]))
label1.pack()
bouton1 = tk.Button(text="OK", command = on_click(label1))
bouton1.pack()
root.mainloop() |