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 40 41 42 43
| from Tkinter import *
import threading
import time
from sys import modules
progmain = modules['__main__']
global calcul_running , temps # le temps est calculé par le
thread et affiché dans la fenêtre
def thread1():
progmain.temps = 0.
while 1:
progmain.temps = progmain.temps +1. # incrémentation du temps
time.sleep (1.)
def start_thread():
progmain.calcul_running = 0
t1=threading.Thread(target=thread1)
t1.start()
def stop_thread():
progmain.calcul_running = 1
# debut du prog
root = Tk()
temps=0.
# label d'affichage du temps ....
c'est sûrement là qu'il faut rajouter des choses
afficheur = Label(root, font = ("Arial",15),text = temps)
afficheur.pack()
# l'objectif est que l'afficheur soit mis à jour
quand le thread incrémente le temps
Bouton_start=Button(root,text='Démarrer le calcul',command=start_thread)
Bouton_start.pack()
Bouton_stop=Button(root,text='Arrêter le calcul',command=stop_thread)
Bouton_stop.pack()
root.mainloop() |
Partager