| 1 |
import gi |
| 2 |
|
| 3 |
gi.require_version("Gtk", "4.0") |
| 4 |
from gi.repository import Gtk |
| 5 |
|
| 6 |
|
| 7 |
class SpinnerAnimation(Gtk.ApplicationWindow): |
| 8 |
def __init__(self, **kargs): |
| 9 |
super().__init__(**kargs, title="Spinner Demo") |
| 10 |
|
| 11 |
button = Gtk.ToggleButton(label="Start Spinning") |
| 12 |
button.connect("toggled", self.on_button_toggled) |
| 13 |
button.props.active = False |
| 14 |
|
| 15 |
self.spinner = Gtk.Spinner() |
| 16 |
|
| 17 |
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, homogeneous=True) |
| 18 |
box.append(button) |
| 19 |
box.append(self.spinner) |
| 20 |
self.set_child(box) |
| 21 |
|
| 22 |
def on_button_toggled(self, button): |
| 23 |
if button.props.active: |
| 24 |
self.spinner.start() |
| 25 |
button.set_label("Stop Spinning") |
| 26 |
|
| 27 |
else: |
| 28 |
self.spinner.stop() |
| 29 |
button.set_label("Start Spinning") |
| 30 |
|
| 31 |
|
| 32 |
def on_activate(app): |
| 33 |
win = SpinnerAnimation(application=app) |
| 34 |
win.present() |
| 35 |
|
| 36 |
|
| 37 |
app = Gtk.Application(application_id="com.example.App") |
| 38 |
app.connect("activate", on_activate) |
| 39 |
|
| 40 |
app.run(None) |