0

I am working for my class project using Pything and Qt5

I am working on project if calculating student's results

So I have many text area called with ( oral1, oral2, oral3... oral14)

So I want to easly jump from one to another using the trick of changing the value of a variable every time the loop ends and put it the reference that the orther variable oral get it's value

Here is my work example: `

from PyQt5 import QtCore, QtGui, QtWidgets
from bullCalcul import*
import sys



def calcul():
    for i in range(1,15):
        Noral = "oral" + str(i)
        Ntp = "tp" + str(i)
        Nde = "de" + str(i)
        Nct = "ct" + str(i)
        Nctt = "ctt" + str(i)
        Nsyn = "syn" + str(i)
        print(Noral)


        oral = ui.Noral.text
        tp = ui.Ntp.text
        de = ui.Nde.text
        ct = ui.Nct.text
        ctt = ui.Nctt.text
        syn = ui.Nsyn.text


app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
ui.pushButton.clicked.connect(calcul)
sys.exit(app.exec_())

So I hope find anyone can understand what exactly am asking about.

Edit : Solution By exemple : noral = getattr(ui, "oral{}".format(i)).text()

thanks to– eyllanesc

koukou
  • 45
  • 7

0 Answers0