Bonjour,

Je veux ajouter une fonction qui est dans un bouton , pour ne pas devoir appuyer sur ce bouton au début.
Ne comprenant pas tout avec tk pouvez vous apporter votre codage :

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
47
class Clock(tk.Label):
    _timer = None
    _ctime = None
 
    def __init__(self, *args, **kwds):
        tk.Label.__init__(self, *args, **kwds)
 
 
    def _update(self, delay=200):
        now = time.strftime("%H:%M:%S")
        self['text']='(... Reception serie ...)'
        # command serie debut :
        #rcv = port.read(50)
        if rcv != "":
            ofu = open("/home/pi/Rs_Arduino/rcv.txt","a")
	    tt=time.strftime("%d/%m/%y;%H;%M;")
	    data=tt+rcv
            ofu.write(data)
            ofu.close()
        # command serie fin :
        if self._ctime != now:
            self._ctime = self['text'] = now
        self._timer = self.after(delay,self._update)
 
    def do_start(self):
        if not self._timer:
            self['text']='(... Reception serie ...)'
            self._update()
 
    def do_stop(self):
        if self._timer:
            self.after_cancel(self._timer)
            self['text'] = '(... Stop ...)'
            self._timer = None
 
    def destroy(self):
        self.do_stop()
        tk.Label.destroy(self)
 
if __name__ == '__main__':
    root = tk.Tk()
    root.title("Bus")
    clock = Clock()
    clock.pack()
    #tk.Button(text='Debut de trame => (...1...0)', command=clock.do_start).pack()
    tk.Button(text='Fin de trame => (nul..nul)', command=clock.do_stop).pack()
    tk.mainloop()
#tk.Button(text='Debut de trame => (...1...0)', command=clock.do_start).pack()
C'est la fonction do_start qu'il faut démarrer avec def __init__(self, *args, **kwds):


@+
Cdlt