0
我正在創建一個爲用戶創建和設置測試的PyQt應用程序。但是,在設置測試問題時,我希望每個頁面可以查看1個問題。例如,如果用戶要開始測試,則會出現問題。一旦他們回答了這個問題,然後他們點擊一個按鈕'Proceed'
,該按鈕顯示下一頁僅顯示第二個問題,依此類推......但是,就我而言,我並不知道每個測試中有多少個問題,所以頁數會有所不同。我正在使用切換佈局,因爲我寧願切換佈局而不是打開新窗口,但這意味着我必須爲每個問題創建一個類,並且由於每個測試的問題不盡相同,我不確定我將如何提出問題? ?如何在每頁顯示Test_Question(String)? (PyQt/Python)
我不打算複製我的整個應用程序的代碼,但將提供以下一個基本的例子:
import sys
from PyQt4 import QtCore, QtGui
class StartTest(QtGui.QMainWindow):
def __init__(self, parent=None):
super(StartTest, self).__init__(parent)
self.central_widget = QtGui.QStackedWidget()
self.setCentralWidget(self.central_widget)
question1 = Question1(self)
self.central_widget.addWidget(question1)
self.central_widget.setCurrentWidget(question1)
question1.proceed.clicked.connect(self.question2)
def question2(self):
question2 = Question2(self)
self.central_widget.addWidget(question2)
self.central_widget.setCurrentWidget(question2)
class Question1(QtGui.QWidget):
def __init__(self, parent=None):
super(Question1, self).__init__(parent)
question = QtGui.QLabel('What is 5+5?')
self.proceed = QtGui.QPushButton("Proceed")
self.Answer = QtGui.QLineEdit(self)
layout = QtGui.QFormLayout()
layout.addRow(question, self.Answer)
layout2 = QtGui.QVBoxLayout()
layout2.addLayout(layout)
layout2.addWidget(self.proceed)
self.setLayout(layout2)
class Question2(QtGui.QWidget):
def __init__(self, parent=None):
super(Question2, self).__init__(parent)
question = QtGui.QLabel('What is 45+10?')
self.proceed = QtGui.QPushButton("Proceed")
self.Answer = QtGui.QLineEdit(self)
layout = QtGui.QFormLayout()
layout.addRow(question, self.Answer)
layout2 = QtGui.QVBoxLayout()
layout2.addLayout(layout)
layout2.addWidget(self.proceed)
self.setLayout(layout2)
#....
if __name__ == '__main__':
User = ''
app = QtGui.QApplication([])
window = StartTest()
window.showFullScreen()
app.exec_()