import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk def on_checkbutton_toggled(checkbutton, data): if checkbutton.get_active(): print("Check button is selected") else: print("Check button is deselected") window = Gtk.Window() button = Gtk.CheckButton(label="Check Button") button.connect("toggled", on_checkbutton_toggled, None) window.add(button) window.show_all() Gtk.main()
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk def on_checkbox_group_toggled(button, data): for widget in button.get_group(): if widget != button: widget.set_active(button.get_active()) window = Gtk.Window() box = Gtk.Box() for i in range(3): button = Gtk.CheckButton(label="Check Button {}".format(i+1)) button.connect("toggled", on_checkbox_group_toggled, None) box.add(button) window.add(box) window.show_all() Gtk.main()In both examples, we import the Gtk module from gi.repository. We create a CheckButton widget using the Gtk.CheckButton class and add it to a window or box container. We connect the widget to a callback function using the connect() method, which is triggered when the button state changes. The callback function receives the widget and any additional data as parameters. Finally, we start the Gtk main loop using the Gtk.main() function.