3.3 show_question() function of Trivia class
The show_question() function of the Trivia class is used to display questions. It mainly includes three parts: displaying the question frame, displaying the question content and displaying the question options.
3.3.1 Display the frame of the question
In the show_question() function, the frame of the question is displayed through the following code.
print_text(font1, 210, 5, "TRIVIA GAME")
print_text(font2, 190, 500-20, "Press Keys (1-4) To Answer", purple)
print_text(font2, 530, 5, "SCORE", purple)
print_text(font2, 550, 25, str(self.score), purple)
The above code displays the framework of the question by calling the print_text() function of the Trivia class, as shown in Figure 2①-④.
Figure 2 Question framework
3.3.2 Display question content
In the show_question() function, the content of the question is displayed through the following code.
question = self.current
print_text(font1, 5, 80, "QUESTION " + str(question))
print_text(font2, 20, 120, self.data[self.current], yellow)
font1 and font2 are two fonts defined in the program. Because the question content is in the current line of data data, str(question) represents the question number, and self.data[self.current] represents the content of the question, as shown in Figure 3① and Figure 3②.
Figure 3 Question content