I would like to open website in standard browser of operating system when user clicks a button in my pyqt4 application. How can I do this?
Asked
Active
Viewed 7,573 times
2 Answers
24
you can use the python webbrowser module
import webbrowser
webbrowser.open('http://stackoverflow.com')

Nikolaus Gradwohl
- 19,708
- 3
- 45
- 61
7
You can also use QDesktopServices::openUrl
.
Here's the minimal working example,
from PyQt5.Qt import QApplication, QUrl, QDesktopServices
import sys
app = QApplication(sys.argv)
url = QUrl("https://stackoverflow.com/questions/3684857/pyqt4-open-website-in-standard-browser-on-button-click")
QDesktopServices.openUrl(url)

Coiby
- 425
- 5
- 9
-
For PyQt6 the imports are: `from PyQt6.QtCore import QUrl` `from PyQt6.QtGui import QDesktopServices` – Ashark Jun 04 '23 at 00:18