所以我正在做一个测验作为学校的项目,它从数据库浏览器(SQlite)中选择已经提出的问题并使用tkinter显示它们。当我运行测验时,会显示所有图形,然后当我输入我的答案并提交时,会出现此错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
File "S:\year 13\computing project\project\MAIN PROJECT CODE.py", line 126, in confirmAnswer
if self.Qn < self.recordNum:
TypeError: unorderable types: int() < Label()
这只是代码片段,所以如果整个代码,请说谢谢你的帮助!
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:
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 :(得分:1)
尝试替换
if self.Qn < self.recordNum:
与
if self.Qn < self.recordNum['text']: