我制作了这个包含单选按钮的向导。单击它时,完成按钮应返回已检查为文本的单选按钮列表!
输入(它是可读性的虚拟输入)
data=[['a','b','c'],['e','f'],['g','f']]
data1 = ['one','two','three']
这是我的代码
from PyQt4 import QtGui, QtCore
def page3arg(x, n):
page = QtGui.QWizardPage()
page.setTitle("{}".format(x))
page.setSubTitle("Please choose one of these state.")
rd1 = QtGui.QRadioButton(page)
rd2 = QtGui.QRadioButton(page)
rd3 = QtGui.QRadioButton(page)
layout = QtGui.QGridLayout()
layout.addWidget(rd1, 2, 0)
layout.addWidget(rd2, 2, 1)
layout.addWidget(rd3, 2, 2)
rd1.setText(' {}'.format(n[0]))
rd2.setText(' {}'.format(n[1]))
rd3.setText(' {}'.format(n[2]))
page.setLayout(layout)
return page
def page2arg(x, n):
page = QtGui.QWizardPage()
page.setTitle("{}".format(x))
page.setSubTitle("Please choose one of these state.")
rd1 = QtGui.QRadioButton(page)
rd2 = QtGui.QRadioButton(page)
layout = QtGui.QGridLayout()
layout.addWidget(rd1, 2, 0)
layout.addWidget(rd2, 2, 1)
rd1.setText(' {}'.format(n[0]))
rd2.setText(' {} .'.format(n[1]))
page.setLayout(layout)
return page
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
wizard = QtGui.QWizard()
wizard.setStyleSheet(("font:50 10pt \"MS Shell Dlg 2\";"))
for m in range(len(data1) - 1):
x = data1[m]
n= data[m]
if len(n) == 3:
page3 = page3arg(x, n)
wizard.addPage(page3)
elif len(n) == 2:
page2 = page2arg(x, n)
wizard.addPage(page2)
wizard.show()
sys.exit(wizard.exec_())
如何编写一个函数,最终将单选按钮的选择作为列表获取。
单选按钮选择列表应如下所示:
output = ['a','e','g']