我正在做一个测验,我希望单选按钮位于不同的位置。我让它在一定程度上工作,因为它在第一个问题中是随机顺序的,但是它会在剩下的测验中保持这个顺序。我希望它每次都随机化。
class MultipleChoice(QtGui.QWidget):
showTopicsSignal = pyqtSignal()
def __init__(self,parent=None):
super(MultipleChoice, self).__init__(parent)
self.initUI()
def initUI(self):
self.Questions=[]
self.Questionum = QLabel()
self.Questioninfo = QLabel()
self.Correctanswer = QRadioButton()
self.Incorrectans1 = QRadioButton()
self.Incorrectans2 = QRadioButton()
self.Incorrectans3 = QRadioButton()
self.Correctanswer.setAutoExclusive(True)
self.Incorrectans1.setAutoExclusive(True)
self.Incorrectans2.setAutoExclusive(True)
self.Incorrectans3.setAutoExclusive(True)
layout = QVBoxLayout(self)
layout.addWidget(self.Questionum)
layout.addWidget(self.Questioninfo)
randomnumber = randint(0,3)
if randomnumber == 0:
layout.addWidget(self.Correctanswer)
layout.addWidget(self.Incorrectans1)
layout.addWidget(self.Incorrectans2)
layout.addWidget(self.Incorrectans3)
elif randomnumber == 1:
layout.addWidget(self.Incorrectans1)
layout.addWidget(self.Correctanswer)
layout.addWidget(self.Incorrectans2)
layout.addWidget(self.Incorrectans3)
elif randomnumber == 2:
layout.addWidget(self.Incorrectans1)
layout.addWidget(self.Incorrectans2)
layout.addWidget(self.Correctanswer)
layout.addWidget(self.Incorrectans3)
elif randomnumber == 3:
layout.addWidget(self.Incorrectans1)
layout.addWidget(self.Incorrectans2)
layout.addWidget(self.Incorrectans3)
layout.addWidget(self.Correctanswer)