0
我創建一個窗口,讓我當我按下一個按鈕添加文本框一個陣列,但是當我按下按鈕,調用函數,我得到一個錯誤,它說「IndicSelectWindow」對象有沒有屬性「無所謂」。我嘗試了其他更簡單的方法,例如更改標籤所說的內容,但我也無法訪問標籤。我怎麼能解決它?請... :(如何訪問框架的要素,如果這些被放置在佈局(HBoxLayout())
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,我推薦閱讀弗洛機翼來提高你的問題:我如何問一個很好的問題(https://stackoverflow.com/help/how-to-ask) – eyllanesc
對不起,我忘了,但我得到了它。如果我能幫上忙,那就太好了。 –
對於當我解決問題,我建議你做[旅遊](https://stackoverflow.com/tour) – eyllanesc