• [^] # Re: Désoler jai oublier un truc

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

    Ca marche pas beaucoup mieux


    import sys, gtk, threading

    def test(*args):
    dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_OK, "Plop")
    dialog.run()
    dialog.destroy()

    class Thread(threading.Thread):
    def __init__(self):
    threading.Thread.__init__(self)

    def run(self):
    gtk.gdk.threads_enter()
    test()
    gtk.gdk.threads_leave()

    return

    class Main(gtk.Window):
    def __init__(self):
    gtk.gdk.threads_init()

    gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
    b1 = gtk.Button("gtk.Dialog dans le thread principal")
    b2 = gtk.Button("gtk.Dialog dans un autre thread")
    h = gtk.HButtonBox()

    b1.connect("clicked", test)
    b2.connect("clicked", self.thread)

    h.pack_start(b1)
    h.pack_start(b2)

    self.add(h)
    self.show_all()

    gtk.main()

    def thread(self, btn):
    t = Thread()
    t.start()

    Main()



    Le plus étrange, c'est que ça fonctionne la première fois, mais pas la deuxième.

    Merci quand même :)