The script shows how to create a context menu in a GTK3 app. Users can activate the menu by right-clicking an item in a treeview.
- Define a treeview list with two columns.
- For the treeview, call the handler
self.RowClick_event
when the eventbutton-press-event
is trigged by the user clicking either the left or right mouse button. - In the handler
RowClick_event(self, widget, event=None)
, useevent.button1
to detect a left-click (normal click) andevent.button1
to detect a right-click (activating the context menu). - Define a context menu and attach it to the treeview by the following:
self.ctxmenu.attach_to_widget(self.tview,None)
Three menu items, namely Move up, Move down and Delete, are defined in the menu. The actual codes for these items are given inself.callback
. A separator is also defined to separate the Delete option from others. - Define a confirmation dialog for the delete operation issued by the context menu.
No comments:
Post a Comment