Search code examples
python-3.xpygtkgtk3pygobjectgobject

Pausing a Thread on PyGTK


I have a button that when it is clicked, it starts a GObject thread that calls a function every 2 seconds. I want to have another button that pauses or stops the calling of this function. Can anyone lead me in the right direction?

Using Python GTK 3

def on_refreshbutton_clicked(self,widget):
    print("Data..")
    self.th = GObject.timeout_add(2000,self.refresh_screen)

def on_pausebutton_clicked(self,widget):
    print("Paused..")

Solution

  • Found the answer. Revome the source!

    def on_refreshbutton_clicked(self,widget):
        print("Data..")
        self.th = GObject.timeout_add(2000,self.refresh_screen)
    
    def on_pauseButton_clicked(self, widget):
        print("Paused main screen.")
        GObject.source_remove(self.th)