Understand the logic of a simple pyqt5 interface inside a script
-
Hello,
I have a python script which does calculations, and from the results it shows an interface (created using pyqt5) that shows part of this information using QLineEdit, allows to call some functions (to do some calculations) and then if accepted continue the code.
I am not used to object oriented programation so I did this as I have learned to program (my excuses for the veterans out there) , that it is not python style at all. while browsing over internet for tutorials on how to do a windows dialog using pyqt5, several of them use a class to define the function,etc, if possible I would like some feedback of why going that route and if possible, for a simple case like the one I put in the script below, to 'translate' it to the class style so I can construct and understand from that.from PyQt5.QtWidgets import QWidget, QMessageBox from PyQt5 import QtCore, QtGui import PyQt5.QtCore as QtCore from PyQt5.QtWidgets import * from PyQt5.QtCore import Qt listOfValues=[1,2,3,4] finalResults=[[] for x in range(len(listOfValues))] def hideDisplay(): dialog.hide() def clicked(): for i in range(len(listOfValues)): inputsLines_0[i].setText(str(int(inputsLines_0[i].text())+1)) def printFunction(): for i in range(len(inputsLines_0)): finalResults[i]=int(inputsLines_0[i].text()) dialog = QDialog() dialog.setWindowTitle("Input size") layout_0 = QGridLayout(dialog) inputsLines_0=[] for i in range(len(listOfValues)): inputsLines_0.append(QLineEdit(str(listOfValues[i]))) layout_0.addWidget(inputsLines_0[i],0,i) addButton=QPushButton("+1") layout_0.addWidget(addButton,0,len(listOfValues)+1) addButton.clicked.connect(clicked) okbox = QDialogButtonBox(dialog) okbox.setOrientation(QtCore.Qt.Horizontal) okbox.setStandardButtons(QDialogButtonBox.Cancel|QDialogButtonBox.Ok) okbox.accepted.connect(printFunction) okbox.rejected.connect(hideDisplay) layout_0.addWidget(okbox,1,0)