# Importing necessary libraries import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject # Creating the button button = Gtk.Button() # Setting the button label button.set_label("Click me!") # Connecting a callback function to the button def on_button_clicked(button): print("Button clicked!") button.connect("clicked", on_button_clicked)
# Importing necessary libraries import gi gi.require_version('Gtk', '3.0') from gi.repository import GObject # Defining a new object with properties and signals class MyObject(GObject.GObject): __gproperties__ = { "property1": (GObject.TYPE_STRING, "Property 1", "Description of property 1", "default value", GObject.PARAM_READWRITE), "property2": (GObject.TYPE_INT, "Property 2", "Description of property 2", 0, 100, 0, GObject.PARAM_READWRITE), } __gsignals__ = { "event1": (GObject.SIGNAL_RUN_FIRST, None, ()), "event2": (GObject.SIGNAL_RUN_FIRST, None, (GObject.TYPE_STRING,)), } def __init__(self): GObject.GObject.__init__(self) # Implementing the property getters and setters def do_get_property(self, prop): if prop.name == "property1": return self._property1 elif prop.name == "property2": return self._property2 def do_set_property(self, prop, value): if prop.name == "property1": self._property1 = value elif prop.name == "property2": self._property2 = value # Implementing the signal handlers def do_event1(self): print("Event 1 triggered") def do_event2(self, arg): print("Event 2 triggered with argument:", arg)In conclusion, Python gi.repository GObject is a package library for creating object-oriented code in graphical user interfaces. It is a part of the GNOME development platform and can be used for desktop applications, including those written in Python. The examples provided showcase the usage of GObject in creating a button in the GUI and a custom object with properties and signals.