功能无法使用sql和tkinter(测验)

时间:2018-04-24 08:21:24

标签: python tkinter sqlite

在函数confirmAnswer上,它会更新问题,但不会向用户显示他们的答案是正确还是不正确,这让我觉得它正在直接跳到此行,if self.Qn < self.recordNum['text']: on相同的功能。

我目前在数据库中只有两个问题,允许测试更容易,当问题更新时,当输入答案时,提交按钮不起作用,而测验应该结束并显示相同的分数功能

我包含了这么多代码,因为我认为理解代码会更有意义,如果它太多而且很抱歉,如果遇到混乱,那就很抱歉。谢谢你的帮助!

def quiz(self):
    self.newf.pack_forget()
    self.head['text'] = 'Welcome to the psychology revision quiz'
    self.quizf.pack()

    self.quizScore = 0
    self.correctAnswer = ''  # <-- create it at start (and use better name)
    self.Qn = 1
    self.update_question()# <-- get new question
    self.update_question_number()
def update_question_number(self):
    # Get question's number

    query = "SELECT MAX(qnumber) FROM questions"
    c.execute(query)
    row = c.fetchone()

    self.recordNum['text'] = row[0]

def update_question(self):
    # Get new question

    query = "SELECT * FROM questions WHERE qnumber=?"
    c.execute(query, (self.Qn,))
    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]    

def confirmAnswer(self):
    self.rightOrWrong = self.enterAnswer
    if self.enterAnswer == self.correctAnswer:
        self.rightOrWrong['text'] = "Correct"
        self.quizScore += 1
        self.update_question()
    else:
        self.rightOrWrong['text'] = "Incorrect"

    if self.Qn < self.recordNum['text']:
        self.Qn += 1           # <-- get new question
        self.update_question() # <-- get new question

    else:
        self.rightOrWrong['text'] = "Quiz Complete! Your score was: {}".format(self.quizScore)

0 个答案:

没有答案