'How do I fix pyqt web browser not loading pages
I am trying to make a web browser using pyqt, but every time I click a url it just does not do anything, that or it crashes. For example if I try to open wikipedia or anything like that it simply refuses to load, and if I Dare to click more than once it crashes. This is the code:
import sys
from PyQt5 import QtCore
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtCore import *
import urllib.request
class Window(QMainWindow):
def __init__(self):
super(Window,self).__init__()
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.browser = QWebEngineView()
self.browser.setUrl(QUrl('https://sites.google.com/view/yevnilc-search/home'))
self.setCentralWidget(self.browser)
self.showMaximized()
navbar = QToolBar()
self.addToolBar(navbar)
prevBtn = QAction('Prev',self)
prevBtn.triggered.connect(self.browser.back)
navbar.addAction(prevBtn)
nextBtn = QAction('Next',self)
nextBtn.triggered.connect(self.browser.forward)
navbar.addAction(nextBtn)
refreshBtn = QAction('Refresh',self)
refreshBtn.triggered.connect(self.browser.reload)
navbar.addAction(refreshBtn)
homeBtn = QAction('Home',self)
homeBtn.triggered.connect(self.home)
navbar.addAction(homeBtn)
self.searchBar = QLineEdit()
self.searchBar.returnPressed.connect(self.loadUrl)
navbar.addWidget(self.searchBar)
self.browser.urlChanged.connect(self.updateUrl)
def home(self):
self.browser.setUrl(QUrl('https://sites.google.com/view/yevnilc-search/home'))
def loadUrl(self):
global x
x = str(url = self.searchBar.text())
self.browser.setUrl(QUrl(url))
def updateUrl(self, url):
self.searchBar.setText(url.toString())
MyApp = QApplication(sys.argv)
QApplication.setApplicationName('Yevnilc Sail')
window = Window()
MyApp.exec_()
Is there a way to fix it
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
