import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk # Create button button = Gtk.Button(label="Click me!")
# Define function to handle button click def on_button_clicked(widget): print("Button clicked!") # Connect button clicked event to function button.connect("clicked", on_button_clicked)
# Create image image = Gtk.Image.new_from_file("my_image.png") # Create button with image button = Gtk.Button(image=image)This code creates a Gtk Image widget from a file and then sets it as the image for the button. When the button is displayed, the image will appear on it. In conclusion, the Gtk Button is a useful component in the gi.repository package of Python that can be used to create clickable buttons in GUI applications.