2019-05-23 22:48:56 +02:00
# Falkon Python Tutorial - 4. Adding entry to the extension menu
2019-05-24 23:44:20 +02:00
Hello, in this chapter I will show you how to add an entry to the extension menu.
2019-05-23 22:53:11 +02:00
The extension menu is located at `Tools` : `Extensions` .
2022-04-27 22:49:06 +02:00
![Extension menu ](../images/py_tutorial4/ExtensionMenu.png )
2019-05-24 23:44:20 +02:00
In this example extension you will see popup [message box ](https://doc.qt.io/qtforpython/PySide2/QtWidgets/QMessageBox.html ) with 'Tutorial 4 - Message from extension menu' after you click on the menu entry.
2022-04-27 22:49:06 +02:00
![Extension menu ](../images/py_tutorial4/MessageBox.png )
2019-05-24 23:44:20 +02:00
2019-05-23 22:48:56 +02:00
To add an entry to extension menu the `populateExtensionsMenu(self, menu)` method has to be implemented in plugin class.
2019-05-23 22:53:11 +02:00
The reason can be found in the [source code ](https://github.com/KDE/falkon/blob/master/src/lib/plugins/plugininterface.h )
2019-05-23 22:48:56 +02:00
The parameter menu is the menu into which the new entry / action will be added.
```python
def populateExtensionsMenu(self, menu):
action = Falkon.Action(
"Tutorial 4 - Extension menu entry",
menu
)
action.triggered.connect(self.onExtensionMenuTriggered)
menu.addAction(action)
def onExtensionMenuTriggered(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setText('Tutorial 4 - Message from extension menu')
msgBox.exec_()
```
2022-04-27 22:49:06 +02:00
The full code can be found at [extensions/Tutorial4 ](../extensions/py_tutorial4 )
2019-05-23 22:48:56 +02:00
**Note:** Always create an instance of Action in `populateExtensionsMenu` .
2019-05-23 23:09:15 +02:00
It will be deleted / destroyed when the menu is hidden.
Do **not** try to add keyboard shortcut to the action used to construct the menu, it will not work properly.