【发布时间】:2016-09-03 18:06:34
【问题描述】:
以下是可能添加的输入示例。
值 0:[ 0 ] [ 100 ]
值 1:[ 200 ] [ 300 ]
值 2:[ 400 ] [ 500 ]
以上是正确的
值 0:[ 0 ] [ 800 ]
值 1:[ 700 ] [ 600 ]
值 2:[ 500 ] [ 400 ]
以上不正确:确保每个值都高于上一个
下面的代码将用户输入的每个值添加到数组中。
def val_norm(self, MainWindow, count):
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setMargin(11)
self.verticalLayout_2.setSpacing(6)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setMargin(11)
self.horizontalLayout_2.setSpacing(6)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.norm_label = QtGui.QLabel(self.Normalization)
self.norm_label.setObjectName(_fromUtf8("norm_label"))
self.horizontalLayout_2.addWidget(self.norm_label)
self.norm_spinBox_[(count*2)-1] = QtGui.QSpinBox(self.Normalization) # All the left side boxes
self.norm_spinBox_[(count*2)] = QtGui.QSpinBox(self.Normalization) # All the right side boxes
self.norm_spinBox_[(count*2)-1].setMaximum(1000) # set the maximums for the left side
self.norm_spinBox_[(count*2)].setMaximum(1000) # set the maximums for the right side
self.horizontalLayout_2.addWidget(self.norm_spinBox_[(count*2)-1]) # adding the actual object to UI (left)
self.horizontalLayout_2.addWidget(self.norm_spinBox_[(count*2)]) # adding the actual object to UI (right)
self.verticalLayout_2.addLayout(self.horizontalLayout_2) # setting up layout
self.verticalLayout.addLayout(self.verticalLayout_2) # setting up layout
# for debugging purposes
self.norm_spinBox_[(count*2)-1].editingFinished.connect(lambda: print(self.norm_spinBox_[(count*2)-1].text()))
self.norm_spinBox_[(count*2)].editingFinished.connect(lambda: print(self.norm_spinBox_[(count*2)].text()))
self.norm_label.setText(_translate("MainWindow", "Value {}".format(self.count), None))
self.count += 1
if self.norm_spinBox_[(count*2)-1].text() > self.norm_spinBox_[count*2].text():
print("That's wrong!")
我认为使用 if 语句会起作用,但我显然误会了我应该如何处理这个问题。如果我错了,请纠正我,但我认为它不起作用,因为我没有在编辑后将 if 语句连接到每个框。
if self.norm_spinBox_[(count*2)-1].text() > self.norm_spinBox_[count*2].text():
print("That's wrong!")
【问题讨论】: