【发布时间】:2018-04-02 20:26:51
【问题描述】:
我正在创建一个窗口,允许我在按下按钮时添加一组文本框,但是当我按下按钮并调用该函数时,我收到一个错误,提示“IndicSelectWindow”对象没有属性“随便”。我尝试其他更简单的方法,例如更改标签的内容,但我也无法访问标签。我该怎么做才能解决它?请... :(
import sys
from PyQt4.QtGui import *
class IndicSelectWindow(QDialog):
def __init__(self, parent=None):
super(IndicSelectWindow, self).__init__(parent=parent)
# cero un layout vertical para las matrices
layoutmatrices = QVBoxLayout()
##########################
# create the area for the matrix
scrollarea = QScrollArea()
scrollarea.setWidgetResizable(True)
widgetdelscrollarea = QWidget()
layoutgrilla = QGridLayout(widgetdelscrollarea)
scrollarea.setWidget(widgetdelscrollarea)
###########################
# now now place elements in the array layout
#the elements consist of a layout where the buttons are placed and another layout where the area is placed
layoutelementosmatriz1 = QHBoxLayout()
labelm1 = QLabel("Matriz 1")
labelmf1 = QLabel("Filas")
labelmc1 = QLabel("Columnas")
botonm1 = QPushButton("Aceptar")
text_m1f = QLineEdit()
text_m1c = QLineEdit()
layoutelementosmatriz1.addWidget(labelm1)
layoutelementosmatriz1.addWidget(labelmf1)
layoutelementosmatriz1.addWidget(text_m1f)
layoutelementosmatriz1.addWidget(labelmc1)
layoutelementosmatriz1.addWidget(text_m1c)
layoutelementosmatriz1.addWidget(botonm1)
layoutelementosmatriz1.setSpacing(20)
botonm1.clicked.connect(lambda: self.create_matrix()) ##eventos
layoutmatrices.addLayout(layoutelementosmatriz1)
layoutmatrices.addWidget(scrollarea)
####################################3 i create the layout for the frame
layoutgeneral = QHBoxLayout()
self.setLayout(layoutgeneral)
self.resize(800, 500)
#################################
# I add the elements to the frame
layoutgeneral.addLayout(layoutmatrices)
###################################
def create_matrix(self): #this method I use to fill the array with "QLineEdit"
self.labelm1.setText("gdsgs")
for i in range(10):
for j in range(10):
self.layoutgrilla.addWidget(QLineEdit(), i, j) #line 18
if __name__ == '__main__':
app = QApplication(sys.argv)
w = IndicSelectWindow()
w.show()
sys.exit(app.exec_())
【问题讨论】:
-
您必须出示您的代码,不幸的是我们不是预言家:P,我建议您阅读以下内容来改善您的问题:How do I ask a good question?
-
对不起,我忘记了,但我知道了。如果我能提供帮助,那就太好了。
-
在我解决问题的同时,我建议您使用tour
-
试试我的答案,如果成功了,别忘了把它标记为正确。
-
非常感谢,效果很好
标签: python pyqt pyqt4 pyqt5 qlabel