0

Hi everyone so as the question says, I have created a browser in python with PyQt5, Python 3.10 on pycharm. the starting of the file is thus:

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl('http://google.com'))
        self.setCentralWidget(self.browser)
        self.showMaximized()

    def go_back(self):
        self.browser.back()

    def go_forward(self):...

and I have imported this browser.py in a different file main.py my question is, see the 'self' argument I defined in each functions? what do I pass in those brackets when calling them from main.py??

I hope you have understood my question I am putting in the easiest way possible...please comment for any confusions

Esvin Joshua
  • 71
  • 14
  • ps: as I am just a beginner in python pls try to understand me. thank you very much – Esvin Joshua Mar 27 '22 at 16:11
  • You don't call functions directly, you have to create an *instance* of the `MainWindow` class (for instance: `window = MainWindow()`) and then call those functions as attributes of that instance (`window.go_back()`). I strongly suggest you to do some research and studying about what classes and instances are, how they work, and the difference between functions and methods in python. Also, read all answers in the post for which yours has been marked as duplicate, possibly by sorting answers by votes. – musicamante Mar 27 '22 at 18:17
  • @musicamante thank you for the clarification. I am now trying out your answer of creating an instance and calling commands with that instance, and also as suggested I am going through the question for which mine has been marked duplicate – Esvin Joshua Mar 28 '22 at 06:20

0 Answers0