import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject def update_label(label): label.set_text("Hello, world!") win = Gtk.Window() label = Gtk.Label() win.add(label) win.show_all() GObject.idle_add(update_label, label) Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject, GLib def long_running_function(): for i in range(10000000): pass def update_label(label): label.set_text("Done!") win = Gtk.Window() label = Gtk.Label() win.add(label) win.show_all() GLib.idle_add(long_running_function) GObject.idle_add(update_label, label) Gtk.main()This example demonstrates running a long running function (`long_running_function`) on the main loop so that it does not block the user interface. After the function has completed, it schedules the `update_label` function to be run which sets the label text to "Done!". The `GLib` package library is also used in this example to access the idle_add function.