Reputation: 368
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?
Upvotes: 10
Views: 8616
Reputation: 555
You can also use QDesktopServices::openUrl
.
Here's the minimal working example,
from PyQt6.QtWidgets import QApplication
from PyQt6.QtCore import QUrl
from PyQt6.QtGui import 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)
If you use Qt5, please import from PyQt5.Qt
from PyQt5.Qt import QApplication, QUrl, QDesktopServices
Upvotes: 8
Reputation: 20124
you can use the python webbrowser module
import webbrowser
webbrowser.open('http://stackoverflow.com')
Upvotes: 24