0
我有一个GUI页面,填充了具有唯一名称的所需数量的lineedit框。我想稍后使用该名称将文本分配给相应的lineedit框。下面是代码:动态GUI页面属性错误
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_LoadsForm3_1(object):
def setupUi(self, LoadsForm3_1):
LoadsForm3_1.setObjectName(_fromUtf8("LoadsForm3_1"))
LoadsForm3_1.resize(500, 500)
self.scrollArea = QtGui.QScrollArea(LoadsForm3_1)
self.scrollArea.setGeometry(QtCore.QRect(20, 180, 450, 250))
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, -293, 250, 500))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.gridLayout = QtGui.QGridLayout(self.scrollAreaWidgetContents)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
for i in range (0,10):
lE="lE0"+str(i)+"_P01"+"E0"+str(i)
self.lE =QtGui.QLineEdit(self.scrollAreaWidgetContents)
self.lE.setObjectName(_fromUtf8(lE))
self.gridLayout.addWidget(self.lE, i, 1, 1, 1)
self.scrollArea.setWidget(self.scrollAreaWidgetContent
self.lE01_P01E01.setText("xyz")
if __name__ == "__main__":
import sys app =QtGui.QApplication(sys.argv)
LoadsForm3_1 = QtGui.QDialog()
ui= Ui_LoadsForm3_1()
ui.setupUi(LoadsForm3_1)
LoadsForm3_1.show()
sys.exit(app.exec_())
但在执行它syas:AttributeError的: 'Ui_LoadsForm3_1' 对象有没有属性 'lE01_P01E01'。我是Pyqt4的新手,我使用python 2.7。任何帮助表示赞赏。谢谢!!!