bonsoir,

Je ne vois pas comment arrêter une boucle avec un bouton
quand la boucle est activée :

Script :

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
40
41
42
43
44
45
46
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
 
from Tkinter import *
import random
import time
import os
 
def affiche():
    f="Nous sommes le %d/%m/%y, il est %H:%M:%S"
    lbl.config(text=time.strftime(f))
    fenetre.after(500,affiche)
 
def debut():
    print "Début"
    time.sleep(3)
    prog()
 
def prog():  
    while True:
        y=random.random()*100
        time.sleep(3)
        print int(y)
 
def arret():
    print "Arrêt"
    system.exit
 
fenetre= Tk()
fenetre.title('Trigger')
fenetre.geometry("280x140")
lbl=Label(fenetre,text="heure")
lbl.place(x=10,y=10)
b1=Button(fenetre, text="Début",width=20, command=debut)
b1.place(x=10,y=40)
b2=Button(fenetre, text="Arrêt",width=20, command=sys.exit)
b2.place(x=10,y=80)
photo1=PhotoImage(file="bullet_green.png")
label1 = Label(image=photo1)
label1.place(x=220,y=38)
photo2=PhotoImage(file="bullet_red.png")
label2 = Label(image=photo2)
label2.place(x=220,y=78)
affiche()
fenetre.mainloop()