import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk def on_option_toggled(widget): if widget.get_active(): print("Option 1 selected") else: print("Option 1 deselected") window = Gtk.Window() box = Gtk.Box() menu = Gtk.Menu() option = Gtk.CheckMenuItem.new_with_label("Option 1") option.connect("toggled", on_option_toggled) menu.append(option) box.add(menu) window.add(box) window.show_all() Gtk.main()In this example, the "toggled" signal is connected to the "on_option_toggled" function, which checks whether the CheckMenuItem is currently selected or not and prints a message accordingly. The Gtk CheckMenuItem is part of the Gtk3 package library.