0

Hi,
I've made a small program which has 2 buttons and each does certain thing. Here's a simplified version of the code.

Thing is it works fine except that the button freezes and stays in a clicked position and whole GUI freezes until the command is completed.
As far as I know threads would be best to use in this situation, but I have no idea how to implement it in this example.

I use glade and pygtk for gui.

def do1:
        t = 2
        #do something
        time.sleep(t)
        #do something
        time.sleep(t)
def do2:
        t = 3
        #do something
        time.sleep(t)
        #do something
        time.sleep(t)
        
class we:
        wTree = None
        def __init__( self ):                
                self.wTree = gtk.glade.XML( "ui.glade" )
                
                dic = {
                        "on_buttonSone" : self.sone,
                        "on_buttonStwo" : self.stwo,
                }
                self.wTree.signal_autoconnect( dic )              
                gtk.main()
                  
        def sone(self, widget):
                i = 0
                while i < 3:
                        t = 1
                        #do something
                        i += 1
                        time.sleep(t)           
                self.wTree.get_widget("entryResult").set_text("Done.")
        def stwo(self, widget):
                start = time.clock()
                array = ['A','B']
                adict = {'A':do1,'B':do2}
                for f in array:
                        adict[f]()
                end = time.clock()
                elapsed = end - start
                gg = round(elapsed,2)             
                self.wTree.get_widget("entryResult").set_text(str(gg))             
             
go=we()
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jcao219
0

You are right, threads are the best way to go.

Just google "python threading" and learn from there.
I don't know anything about it,
I always use the .NET version of threading.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.