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.
- Define a context menu
self.ctxmenuusingGtk.Menu(). Attach it to the treeview. - Define an accelerator group by
Gtk.AccelGroup()and add it to the app window by the functionwindow.add_accel_group(). This group will keep a record of accelerator keys defined later. - Define four menu items, namely Move up, Move down, Delete and Clear all items. Assign the accelerator keys
Ctrl+U,Ctrl+D,DeleteandShift+Ctrl+Deleterespectively to the items using the functionmenuItem.add_accelerator().

No comments:
Post a Comment