如何从self.questions
列表中创建这些if和else语句?我现在想做的是,当程序运行时,每个选项框中都有三个选项框。
我希望用户选择其中一个答案,并根据与所问问题相对应的self.questions
列表中的答案来查看它们是否正确。
def __init__(self):
self.newWindow = self.new_window('QUESTION')
self.window = self.newWindow
#This is a counter for the questions
self.question_counter = 0
#This is the questions, there is a list of questions
self.questions = ["Question One: What is the capital of France?", "Question Two: What martial arts movie was first produced by Hollywood?",
"Question Three: What year did World War II start?", "Question Four: What year did Abraham Licoln get assassinated?"]
#This is the answers, there is a list of three possible answers for each question
self.answers = [["Madrid", "London", "Paris"],
["The Karate Kid", "Enter the Dragon", "Ip Man"],
["1914", "1939", "1940"],
["1865", "1912", "1688"]]
self.label = Label(self.newWindow,
text=self.questions[self.question_counter], font = ("Arial", "24"), pady=30)
self.answer1button = Button(self.window, text=self.answers[self.question_counter][0])
self.answer2button = Button(self.window, text=self.answers[self.question_counter][1])
self.answer3button = Button(self.window, text=self.answers[self.question_counter][2])
答案 0 :(得分:0)
您可以在类内部创建三个方法,每个方法对应一个答案/按钮。在功能内部检查选择的答案是否正确,然后将其添加到问题计数器并显示下一个问题。然后使每个按钮执行与它们相关的功能。