Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am trying to animate a spinner while the programm is running but i can't. I tried using threads but i can't get what i can look here for the progress i made

i get the spinner to animate but the program stops running...

share|improve this question
up vote 0 down vote accepted

I saw your question yesterday on reddit as well.

When I tried to use threads in python and gtk, it took me like one night to figure it out.

In the end it was as simple as


in the beginning and then spawn threads like you normally would in python with something like

watch_thread = Thread(target=self.function)
watch_thread.daemon = True

I have no idea if that helps you. But I do hope so. I will also take a look at your code and might edit my answer afterwards :)

share|improve this answer
i merge your pull request but i didn't work... i have to run both function with thread? (one to start the spinner and the other to execute the commands) edit: it works!!! thanks very much! – Clepto Jul 4 '12 at 15:04

Keep following 2 tips in mind when using threads and PyGTK:

  • Make sure to call GObject.threads_init() as soon as possible in your program to enable threading in your PyGTK app.

  • If you are doing any GUI tasks in your thread, wrap it inside GObject.idle_add(callable), always.

Here is a full working example, adapt to your code as needed:

import time
import threading

from gi.repository import Gtk, GObject
GObject.threads_init() # Don' forget!

class WorkerThread(threading.Thread):
    def __init__(self, callback):
        self.callback = callback

    def run(self):
        # Simulate a long process, do your actual work here

        # The callback runs a GUI task, so wrap it!

class MyWindow(Gtk.Window):
    def __init__(self):
        self.connect('delete-event', Gtk.main_quit)
        self.resize(400, 400)

        vbox = Gtk.VBox()

        button = Gtk.Button("Let's spin!")
        button.connect('clicked', self.on_button_clicked)
        vbox.pack_start(button, False, False, 0)

        self.spinner = Gtk.Spinner()
        vbox.pack_start(self.spinner, True, True, 0)

    def on_button_clicked(self, widget):
        thread = WorkerThread(self.work_finished_cb)

    def work_finished_cb(self):

if __name__ == "__main__":
    app = MyWindow()
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.