我正在进行多项选择测验。我已经制作了带有问题的按钮和文本框以及带有可能答案的文本框。如何将按钮连接到答案以继续下一个问题?
这是我的代码:
from PySide import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(400, 300)
self.centralWidget = QtGui.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
MainWindow.setCentralWidget(self.centralWidget)
#Text Display Window
self.textDisp = QtGui.QTextEdit(self.centralWidget)
self.textDisp.setGeometry(QtCore.QRect(10, 10, 381, 71))
self.textDisp.setReadOnly(True)
self.textDisp.setObjectName("textDisp")
self.textDisp.append('Question 1:')
self.textDisp.append('What is ... ?')
self.horizontalLayoutWidget = QtGui.QWidget(self.centralWidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 90, 171, 80))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayoutWidget = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayoutWidget.setContentsMargins(0, 0, 0, 0)
self.horizontalLayoutWidget.setObjectName("horizontalLayout")
self.textDisp2 = QtGui.QTextEdit(self.centralWidget)
self.textDisp2.setGeometry(QtCore.QRect(10, 100, 381, 71))
self.textDisp2.setReadOnly(True)
self.textDisp2.setObjectName("textDisp2")
self.textDisp2.append('A: ...')
self.textDisp2.append('B: ...')
self.textDisp2.append('C: ...')
self.textDisp2.append('D: ...')
self.horizontalLayoutWidget = QtGui.QWidget(self.centralWidget)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 90, 171, 80))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayoutWidget = QtGui.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayoutWidget.setContentsMargins(0, 0, 0, 0)
self.horizontalLayoutWidget.setObjectName("horizontalLayout")
##
## self.verticalLayoutWidget = QtGui.QWidget(self.centralWidget)
## self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 90, 171, 80))
## self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
##
## self.verticalLayoutWidget = QtGui.QHBoxLayout(self.verticalLayoutWidget)
## self.verticalLayoutWidget.setContentsMargins(0, 0, 0, 0)
## self.verticalLayoutWidget.setObjectName("verticalLayout")
## #Label for Answer 1
## self.ans1 = QtGui.QLabel()
## self.ans1.setObjectName("answer1")
## self.horizontalLayoutWidget.addWidget(self.ans1)
##
## #Input for Answer 1
## self.ans1Input = QtGui.QLineEdit()
## self.ans1Input.setObjectName("answer1Input")
## self.horizontalLayoutWidget.addWidget(self.ans1Input)
self.horizontalLayoutWidget_2 = QtGui.QWidget(self.centralWidget)
self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(219, 90, 171, 80))
self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2")
self.horizontalLayoutWidget_2 = QtGui.QHBoxLayout(self.horizontalLayoutWidget_2)
self.horizontalLayoutWidget_2.setContentsMargins(0, 0, 0, 0)
self.horizontalLayoutWidget_2.setObjectName("horizontalLayout_2")
## #Label for Answer 2
## self.answer2 = QtGui.QLabel()
## self.answer2.setObjectName("number2")
## self.horizontalLayoutWidget_2.addWidget(self.answer2)
##
## #Input for Answer 2
## self.ans2Input = QtGui.QLineEdit()
## self.ans2Input.setObjectName("numb2Input")
## self.horizontalLayoutWidget_2.addWidget(self.ans2Input)
self.gridLayoutWidget = QtGui.QWidget(self.centralWidget)
self.gridLayoutWidget.setGeometry(QtCore.QRect(9, 180, 381, 80))
self.gridLayoutWidget.setObjectName("gridLayoutWidget")
self.gridLayout = QtGui.QGridLayout(self.gridLayoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
#Button for Option A
self.abtn = QtGui.QPushButton(self.gridLayoutWidget)
self.abtn.setObjectName("abtn")
self.gridLayout.addWidget(self.abtn, 0, 0, 1, 1)
self.abtn.setText("A")
## self.abtn.clicked.connect(self.)
#Button for Option B
self.bbtn = QtGui.QPushButton(self.gridLayoutWidget)
self.bbtn.setObjectName("bbtn")
self.gridLayout.addWidget(self.bbtn, 1, 0, 1, 1)
self.bbtn.setText("B")
## self.bbtn.clicked.connect(self.)
#Button for Option C
self.cbtn = QtGui.QPushButton(self.gridLayoutWidget)
self.cbtn.setObjectName("cbtn")
self.gridLayout.addWidget(self.cbtn, 0, 1, 1, 1)
self.cbtn.setText("C")
## self.cbtn.clicked.connect(self.)
#Button for Option D
self.dbtn = QtGui.QPushButton(self.gridLayoutWidget)
self.dbtn.setObjectName("dbtn")
self.gridLayout.addWidget(self.dbtn, 1, 1, 1, 1)
self.dbtn.setText("D")
## self.dbtn.clicked.connect(self.)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())