小测验到10分还没结束

2024-04-18 08:28:52 发布

您现在位置:Python中文网/ 问答频道 /正文

def confirmAnswer(self):
        answer = self.enterAnswer.get() #Obtains what the user has typed into the textbox.
        if answer == self.correctAnswer: #Checks the answer submitted compares to correct answer.
            self.quizScore += 1 # Adds one to score.
            ms.showinfo(title='Correct', message='Correct')
            #self.Qn = self.Qn + 1# This changes to the next question.

            if x == 10:# Question number is one above the number of questions else last question wont work. Ends when it hits 11 as 10 questions.
                ms.showinfo(title="End of test", message = "This is the end of the test. You scored")
            else:
                self.update_question() # Gets next question

        else:
            ms.showwarning(title='Incorrect', message='Incorrect')
            if x == 10:# Question number is one above the number of questions else last question wont work. Ends when it hits 11 as 10 questions.
                ms.showinfo(title="End of test", message = "This is the end of the test. You scored")
            else:
                self.update_question()
                global num
                num = randint(1,10) 

测验应该在第10题结束,然后继续到第11题、第12题等。我在SQL数据库中只有10个问题,我从中调用它们,但每个问题只重复两次。你知道吗

def update_question(self):
        # Get new question
        global num
        num = randint(1, 10)
        query = "SELECT * FROM questions WHERE [qnumber] =?"
        c.execute(query,(num,))
        row = c.fetchone()

        self.question['text'] = row[1]

        self.answer1['text'] = row[2]
        self.answer2['text'] = row[3]
        self.answer3['text'] = row[4]
        self.answer4['text'] = row[5]

        self.correctAnswer = row[6] 

这是一段更新问题的代码。你知道吗

global x
x = IntVar()
x.set(1)
def add():
    x.set(x.get()+1)

self.recordNum = Label(self.quizf, textvariable=x)
self.recordNum.pack()

self.enterAnswer = Entry(self.quizf)
self.Submit = Button(self.quizf, text = 'submit', command=lambda:[self.confirmAnswer(),add()])

这段代码是当按下提交按钮时,问题编号是如何更新的。当x达到10时,它应该结束代码,但继续添加1。你知道吗


Tags: ofthetextanswerselfnumbermessagetitle