I'm relatively new to Python and am currently working on the QtWidget. In my online course we created our own class that inherits from QtWidgets.QMainWindow. When creating the constructor, we created a parameter called Parent, what do we need it for? I've also read the official documentation, but I can't make any sense of it.
This is the code:
import sys
from qtpy import QtWidgets
from ui.mainwindow import Ui_MainWindow
app = QtWidgets.QApplication(sys.argv)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent = None):
super().__init__(parent)
self.setWindowTitle("Test")
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.button.clicked.connect(self.on_button_click)
def on_button_click(self):
self.weight = self.ui.weight.value()
self.height = self.ui.height.value()
if self.weight and self.height != 0:
self.rechnung = (self.weight) / (self.height ** 2)
self.ui.result.setText(f"Dein BMI hat einen Wert von {round(self.rechnung, 2)}")
else:
self.ui.result.setText("Deine eingaben dürfen keine 0 enthalten")
window = MainWindow()
window.show()
sys.exit(app.exec_())
we pass this parameter to the QtWidgets.QMainWindow() class, but for what?