Sunday, 22 May 2022

Accelerator Keys and Context Menu

The script shows how to add accelerator keys to a context menu in a GTK3 app. Users can run the menu items by using shortcut keys such as Ctrl+U and Delete.



  1. Define a context menu self.ctxmenu using Gtk.Menu(). Attach it to the treeview.
  2. Define an accelerator group by Gtk.AccelGroup() and add it to the app window by the function window.add_accel_group(). This group will keep a record of accelerator keys defined later.
  3. Define four menu items, namely Move up, Move down, Delete and Clear all items. Assign the accelerator keys Ctrl+U, Ctrl+D, Delete and Shift+Ctrl+Delete respectively to the items using the function menuItem.add_accelerator().

Source Code


No comments:

Post a Comment