Monday, July 27, 2026
HomeLanguagesPython – Spinner in GTK+ 3

Python – Spinner in GTK+ 3

The Gtk.Spinner displays an icon-size spinning animation. It is often used as an alternative to a GtkProgressBar for displaying an indefinite activity. We can use Gtk.Spinner.start() to start and Gtk.Spinner.stop() to stop the animation.

Example :

Python3




import gi
  
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
  
  
class SpinnerAnimation(Gtk.Window):
    def __init__(self):
  
        Gtk.Window.__init__(self, title="GFG")
        self.set_border_width(3)
        self.connect("destroy", Gtk.main_quit)
  
        self.button = Gtk.ToggleButton(label="Start Spinning")
        self.button.connect("toggled", self.on_button_toggled)
        self.button.set_active(False)
  
        self.spinner = Gtk.Spinner()
  
        self.grid = Gtk.Grid()
        self.grid.add(self.button)
        self.grid.attach_next_to(
            self.spinner, self.button, Gtk.PositionType.BOTTOM, 1, 2
        )
        self.grid.set_row_homogeneous(True)
  
        self.add(self.grid)
        self.show_all()
  
    def on_button_toggled(self, button):
  
        if button.get_active():
            self.spinner.start()
            self.button.set_label("Stop Spinning")
  
        else:
            self.spinner.stop()
            self.button.set_label("Start Spinning")
  
  
myspinner = SpinnerAnimation()
  
Gtk.main()


Output :

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32520 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6903 POSTS0 COMMENTS
Nicole Veronica
12017 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12115 POSTS0 COMMENTS
Shaida Kate Naidoo
7023 POSTS0 COMMENTS
Ted Musemwa
7265 POSTS0 COMMENTS
Thapelo Manthata
6980 POSTS0 COMMENTS
Umr Jansen
6972 POSTS0 COMMENTS