import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject def update_label(): label.set_text('Updated text') win = Gtk.Window() label = Gtk.Label('Original text') win.add(label) win.show_all() # Call `update_label` function every 2 seconds GObject.timeout_add_seconds(2, update_label) Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject def close_win(): win.destroy() win = Gtk.Window() win.show_all() # Close the window after 5 seconds GObject.timeout_add_seconds(5, close_win) Gtk.main()In both examples, we import the gi.repository package and use its GObject module to access the timeout_add_seconds() function. The first example updates a label widget's text every 2 seconds using this function, while the second example closes a window after 5 seconds. In order to use these examples, make sure you have the required package library installed. In this case, that would be the gi.repository package, which is included in the `python3-gi` package on most Linux distributions.