lundi 30 décembre 2019

PyQt5: Taking link to array in web browser

I have to take current link from user to an array and I use this in Back and Forward buttons.

import sys
from PyQt5 import QtCore,QtGui,QtWidgets
from PyQt5 import QtNetwork
from PyQt5 import QtWebEngine
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *

Links = ["https://www.google.com", "https://www.youtube.com", "https://www.facebook.com", "https://www.whatsapp.com"]

class MainWindow(QMainWindow):


    def __init__(self):
        super(MainWindow,self).__init__()

        self.browser=QWebEngineView()
        self.setCentralWidget(self.browser)
        self.adressbar=QtWidgets.QLineEdit(self)
        self.setWindowIcon(QtGui.QIcon('D:\Icons\Star.png'))
        self.browser.setUrl(QUrl('https://www.google.com'))
        self.adressbar.setGeometry(QtCore.QRect(0,0,1500,30))

        searchButton = QPushButton(self)
        searchButton.setIcon(QtGui.QIcon('D:\Icons\Search.png'))
        searchButton.setGeometry(QtCore.QRect(1500,0,30,30))
        searchButton.clicked.connect(self.search_button)

        backButton = QPushButton(self)
        backButton.setIcon(QtGui.QIcon("D:\icons\Back.png"))
        backButton.setGeometry(QtCore.QRect(1530,0,30,30))
        backButton.clicked.connect(self.back_button)

        homeButton=QPushButton(self)
        homeButton.setIcon(QtGui.QIcon("D:\icons\Home.png"))
        homeButton.setGeometry(QtCore.QRect(1560,0,30,30))
        homeButton.clicked.connect(self.home_button)

        forwardButton=QPushButton(self)
        forwardButton.setIcon(QtGui.QIcon("D:\icons\Forward.png"))
        forwardButton.setGeometry(QtCore.QRect(1590,0,30,30))
        forwardButton.clicked.connect(self.forward_button)

        youtubeButton = QPushButton(self)
        youtubeButton.setIcon(QtGui.QIcon("D:\icons\Youtube.png"))
        youtubeButton.setGeometry(QtCore.QRect(1620, 0, 30, 30))
        youtubeButton.clicked.connect(self.youtube_button)

        facebookButton = QPushButton(self)
        facebookButton.setIcon(QtGui.QIcon("D:\icons\Facebook.ico"))
        facebookButton.setGeometry(QtCore.QRect(1650, 0, 30, 30))
        facebookButton.clicked.connect(self.facebook_button)

        whatsappButton = QPushButton(self)
        whatsappButton.setIcon(QtGui.QIcon("D:\icons\Whatsapp.jpg"))
        whatsappButton.setGeometry(QtCore.QRect(1680, 0, 30, 30))
        whatsappButton.clicked.connect(self.whatsapp_button)

        self.showMaximized()

    def search_button(self):
        url = self.adressbar.text()
        self.browser.load(QtCore.QUrl(url))
        self.browser.QWebViewurl()
    def back_button(self):
        self.browser.back()
    def home_button(self):
        self.browser.setUrl(QUrl(Links[0]))
    def forward_button(self):
        self.browser.forward()
    def youtube_button(self):
        self.browser.setUrl(QUrl(Links[1]))
    def facebook_button(self):
        self.browser.setUrl(QUrl(Links[2]))
    def whatsapp_button(self):
        self.browser.setUrl(QUrl(Links[3]))

app = QApplication(sys.argv)
window=MainWindow()
window.show
sys.exit(app.exec_())

I mean when user enter facebook then google then youtube history array take this link and when user press backButton browser will enter google then facebook and if user press forwardButton when in facebook browser will enter google.

If you help me I can be happiest person in the world. Thank you




Aucun commentaire:

Enregistrer un commentaire