Popup Context Menu
| Chapter 8. The TreeView widget |

## Popup Context Menu

Lots of people need to implement right-click context menus for `TreeView`'s so we will explain how to do that here to save you some time. Apart from one or two points, it's much the same as a normal context menu, as described in the menus chapter.

### Handling `button_press_event`

To detect a click of the right mouse button, you need to handle the `button_press_event` signal, and check exactly which button was pressed. Because the `TreeView` normally handles this signal completely, you need to either override the default signal handler in a derived `TreeView` class, or use `connect_nofify()` instead of `connect()`. You probably also want to call the default handler before doing anything else, so that the right-click will cause the row to be selected first.

This is demonstrated in the Popup Custom Menu example.

Drag and Drop |  | Examples