• # Une solution

    Posté par . En réponse au message PyGTK et les threads.. Évalué à 1.

    j'ai réécrit la classe MyThread comme ceci:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import threading, time
    import gobject
    import gtk
    class MyThread:
     def __init__(self, main, nb):
     self.main = main
     self.nb = nb
     self.is_running = False
     def start(self):
     print 'start thread', self.nb
     self.is_running = True
     self.th = threading.Thread(target = self.loop)
     self.th.start()
     def stop(self):
     print 'stop thread', self.nb
     self.is_running = False
     self.th = None
     def loop(self):
     while self.is_running == True:
     gobject.idle_add(self.update_label)
     time.sleep(0.1) 
     def update_label(self):
     # Le but de cette fonction est de montrer comment modifier
     # un objet gtk dans la boucle principale depuis un thread.
     self.main.labels[self.nb-1].set_text(str(time.time()))