Python3.7 Pyqt5で作成したlineEditが12個あり、それぞれのオブジェクト名が
lineEdit_1
lineEdit_2
lineEdit_3
・
・
・
lineEdit_12
というオブジェクト名になっています。
この12個のオブジェクトをfor文を使って値をセットしたいのですが、イメージとして
python
1for i= 1 to 12 2 self.lineEdit_ + i + .setText = i 3next
VBAだと Controls("lineEdit_" & i).value = i のような感じでfor文でループさせれば
きるかと思うのですが、pythonでの書き方がわからずにいます。
ご教授お願い致します。
下記、サンプルソースを記載いたします。
python
1from PyQt5 import QtCore, QtGui, QtWidgets 2 3class Ui_Form(object): 4 def setupUi(self, Form): 5 Form.setObjectName("Form") 6 Form.resize(187, 300) 7 self.lineEdit_1 = QtWidgets.QLineEdit(Form) 8 self.lineEdit_1.setGeometry(QtCore.QRect(40, 30, 113, 20)) 9 self.lineEdit_1.setObjectName("lineEdit_1") 10 self.lineEdit_2 = QtWidgets.QLineEdit(Form) 11 self.lineEdit_2.setGeometry(QtCore.QRect(40, 50, 113, 20)) 12 self.lineEdit_2.setObjectName("lineEdit_2") 13 self.lineEdit_3 = QtWidgets.QLineEdit(Form) 14 self.lineEdit_3.setGeometry(QtCore.QRect(40, 70, 113, 20)) 15 self.lineEdit_3.setObjectName("lineEdit_3") 16 self.lineEdit_4 = QtWidgets.QLineEdit(Form) 17 self.lineEdit_4.setGeometry(QtCore.QRect(40, 90, 113, 20)) 18 self.lineEdit_4.setObjectName("lineEdit_4") 19 self.lineEdit_5 = QtWidgets.QLineEdit(Form) 20 self.lineEdit_5.setGeometry(QtCore.QRect(40, 110, 113, 20)) 21 self.lineEdit_5.setObjectName("lineEdit_5") 22 self.lineEdit_6 = QtWidgets.QLineEdit(Form) 23 self.lineEdit_6.setGeometry(QtCore.QRect(40, 130, 113, 20)) 24 self.lineEdit_6.setObjectName("lineEdit_6") 25 self.lineEdit_7 = QtWidgets.QLineEdit(Form) 26 self.lineEdit_7.setGeometry(QtCore.QRect(40, 150, 113, 20)) 27 self.lineEdit_7.setObjectName("lineEdit_7") 28 self.lineEdit_8 = QtWidgets.QLineEdit(Form) 29 self.lineEdit_8.setGeometry(QtCore.QRect(40, 170, 113, 20)) 30 self.lineEdit_8.setObjectName("lineEdit_8") 31 self.lineEdit_9 = QtWidgets.QLineEdit(Form) 32 self.lineEdit_9.setGeometry(QtCore.QRect(40, 190, 113, 20)) 33 self.lineEdit_9.setObjectName("lineEdit_9") 34 self.lineEdit_10 = QtWidgets.QLineEdit(Form) 35 self.lineEdit_10.setGeometry(QtCore.QRect(40, 210, 113, 20)) 36 self.lineEdit_10.setObjectName("lineEdit_10") 37 self.lineEdit_11 = QtWidgets.QLineEdit(Form) 38 self.lineEdit_11.setGeometry(QtCore.QRect(40, 230, 113, 20)) 39 self.lineEdit_11.setObjectName("lineEdit_11") 40 self.lineEdit_12 = QtWidgets.QLineEdit(Form) 41 self.lineEdit_12.setGeometry(QtCore.QRect(40, 250, 113, 20)) 42 self.lineEdit_12.setObjectName("lineEdit_12") 43 44 self.retranslateUi(Form) 45 QtCore.QMetaObject.connectSlotsByName(Form) 46 47 def retranslateUi(self, Form): 48 _translate = QtCore.QCoreApplication.translate 49 Form.setWindowTitle(_translate("Form", "Form")) 50 51 52if __name__ == "__main__": 53 import sys 54 app = QtWidgets.QApplication(sys.argv) 55 Form = QtWidgets.QWidget() 56 ui = Ui_Form() 57 ui.setupUi(Form) 58 Form.show() 59 sys.exit(app.exec_()) 60 61
回答1件
あなたの回答
tips
プレビュー