在这里,每当用户单击PushButton 'Press me'
时,都会生成一个新的CheckBox。
from PyQt5 import QtWidgets, QtGui, QtCore
count = 1
class Window(QtWidgets.QWidget):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.vlayout = QtWidgets.QVBoxLayout()
self.pushButton1 = QtWidgets.QPushButton("Press me", self)
self.pushButton1.clicked.connect(self.addCheckbox(count))
self.pushButton2 = QtWidgets.QPushButton("OK", self)
self.vlayout.addWidget(self.pushButton1)
self.vlayout.addWidget(self.pushButton2)
self.setLayout(self.vlayout)
def addCheckbox(self,count):
global count
self.vlayout.addWidget(str(count),QtWidgets.QCheckBox())
count = count +1
application = QtWidgets.QApplication(sys.argv)
window = Window()
window.setWindowTitle('Hello')
window.resize(250, 180)
window.show()
sys.exit(application.exec_())
现在您将拥有唯一的复选框,每个复选框具有不同的编号,我想添加更多功能。
每次用户选择特定的复选框时,我想知道用户单击PushButton OK
后单击了哪个复选框。
例如:我点击复选框1
-> OK
-> print 1 on the screen
我该怎么做?
PS:我们需要考虑用户永远不会点击Press me
的可能性,因此不会生成任何折叠框,并且会直接点击OK
答案 0 :(得分:0)
只需使用列表来存储QCheckBox,然后通过迭代进行验证。
Modify Text File - Single File: No Target Chosen
Status: ERROR
Additional Notes: ERROR - Unable to locate ASCII text file to be manipulated. Deferring...
Modify Text File - Single File: No Target Chosen
Status: ERROR
Additional Notes: ERROR - Unable to locate ASCII text file to be manipulated. Deferring...
Install Action: InstallAnywhere Variable
Status: SUCCESSFUL
Install Action: InstallAnywhere Variable
Status: SUCCESSFUL
Check Disk Space: /opt\EpsonJavaPOS
Status: SUCCESSFUL
Additional Notes: NOTE - Required Disk Space: 40,268,671; Free Disk Space: -1
Install Action: Jump To: Next Unit Package Con't -- Prev: NO JUMP
Status: SUCCESSFUL
Modify Text File - Single File: SetupPOS.properties
Status: ERROR
Additional Notes: ERROR - Unable to locate ASCII text file to be manipulated. Deferring...