I've successfully created a script that adds a button to the plugin toolbar in QGIS, by running the script in the python console.
Here is my code:
import webbrowser icon_path = MyPath def open_url(): webbrowser.open(MyURL) action = QAction(name) action.triggered.connect(open_url) action.setIcon(QIcon(icon_path)) iface.addToolBarIcon(action)
I have read that you can make QGIS to add the button when a certain QGIS project is loaded by using 'Project properties' -> 'Macros'.
Though, This won't work for me.
What I have tried is...:
import webbrowser from qgis.PyQt.QtGui import * from qgis.PyQt.QtWidgets import * from qgis.utils import iface def openProject(): url = 'https://google.dk' def show_url(): iface.messageBar().pushMessage() webbrowser.open(url, new=1) action = QAction('Show Time') action.triggered.connect(show_url) action.setIcon(QIcon(MyPath) iface.addToolBarIcon(action)
Can anybode figure out what I am missing in the code for make the Macro work out well?