コード例 #1
0
def showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ, answers, get_anwser):
    answers.append(get_anwser)
    if numberOfQ < len(GameInfoDict['questions'].keys()):
        list = frame.grid_slaves()

        for l in list:
            l.destroy()
        frame = Frame(window)
        frame.grid(row=1, column=1)
        list_of_q = []

        for question_name in GameInfoDict['questions'].keys():
            list_of_q.append(question_name)

        q = list_of_q[numberOfQ]
        question = Label(frame, text=q, fg='black', font='Ariel 16 bold')
        question.grid(row=0, column=0, pady=(10, 10))

        a1_text = GameInfoDict['questions'][q]['answers'][0]
        a1 = Button(frame, text=a1_text, bg="blue", fg="white", width=20, font='Ariel 12 bold',
                    command=lambda: showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                                                 answers, a1_text))
        a1.grid(row=1, column=0, pady=(5, 5))

        a2_text = GameInfoDict['questions'][q]['answers'][1]
        a2 = Button(frame, text=a2_text, bg="blue", fg="white", width=20, font='Ariel 12 bold',
                    command=lambda: showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                                                 answers, a2_text))
        a2.grid(row=2, column=0, pady=(5, 5))

        a3_text = GameInfoDict['questions'][q]['answers'][2]
        a3 = Button(frame, text=a3_text, bg="blue", fg="white", width=20, font='Ariel 12 bold',
                    command=lambda: showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                                                 answers, a3_text))
        a3.grid(row=3, column=0, pady=(5, 5))

        a4_text = GameInfoDict['questions'][q]['answers'][3]
        a4 = Button(frame, text=a4_text, bg="blue", fg="white", width=20, font='Ariel 12 bold',
                    command=lambda: showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                                                 answers, a4_text))
        a4.grid(row=4, column=0, pady=(5, 5))
        right_answer = Label(frame, text=GameInfoDict['questions'][q]['true'], fg='black', font='Ariel 8')
        right_answer.grid(row=5, column=0, pady=(10, 10))
    else:
        del answers[0]
        grade = gL.end(Gamer_name.get(), answers, GameInfoDict, 1)
        list = frame.grid_slaves()
        for l in list:
            l.destroy()
        frame = Frame(window)
        frame.grid(row=1, column=1)
        frame.grid_columnconfigure(0, weight=1)
        frame.grid_rowconfigure(0, weight=1)
        message1 = Label(frame, text='you grade: ' + str(grade), fg='black', font='Ariel 16 bold')
        message1.grid(row=0, column=0, pady=(5, 5))

        bottonEasy = Button(frame, text='Back to menu', bg="green", fg="white", font='Ariel 12 bold',
                            command=lambda: start(window, Gamer_name))
        bottonEasy.grid(row=1, column=0, pady=(5, 5))
コード例 #2
0
def showQuestion(Gamer_name, window, frame, GameInfoDict, numberOfQ, answers,
                 get_anwser, fileBackground2):
    answers.append(get_anwser)
    if numberOfQ < len(GameInfoDict['questions'].keys()):
        list = frame.grid_slaves()

        for l in list:
            l.destroy()
        frame = Frame(window, bg="white")
        frame.grid(row=1, column=1)
        list_of_q = []

        for question_name in GameInfoDict['questions'].keys():
            list_of_q.append(question_name)

        q = list_of_q[numberOfQ]
        question = Label(frame,
                         text=q,
                         fg='black',
                         bg="white",
                         font=("Comic Sans MS", 14))
        question.grid(row=0, column=0, pady=(10, 10))

        a1_text = GameInfoDict['questions'][q]['answers'][0]
        a1 = Button(frame,
                    text=a1_text,
                    bg="#3abdef",
                    fg="white",
                    width=30,
                    font=("Comic Sans MS", 14),
                    command=lambda: showQuestion(
                        Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                        answers, a1_text, fileBackground2))
        a1.grid(row=1, column=0, pady=(5, 5))

        a2_text = GameInfoDict['questions'][q]['answers'][1]
        a2 = Button(frame,
                    text=a2_text,
                    bg="#3abdef",
                    fg="white",
                    width=30,
                    font=("Comic Sans MS", 14),
                    command=lambda: showQuestion(
                        Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                        answers, a2_text, fileBackground2))
        a2.grid(row=2, column=0, pady=(5, 5))

        a3_text = GameInfoDict['questions'][q]['answers'][2]
        a3 = Button(frame,
                    text=a3_text,
                    bg="#3abdef",
                    fg="white",
                    width=30,
                    font=("Comic Sans MS", 14),
                    command=lambda: showQuestion(
                        Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                        answers, a3_text, fileBackground2))
        a3.grid(row=3, column=0, pady=(5, 5))

        a4_text = GameInfoDict['questions'][q]['answers'][3]
        a4 = Button(frame,
                    text=a4_text,
                    bg="#3abdef",
                    fg="white",
                    width=30,
                    font=("Comic Sans MS", 14),
                    command=lambda: showQuestion(
                        Gamer_name, window, frame, GameInfoDict, numberOfQ + 1,
                        answers, a4_text, fileBackground2))
        a4.grid(row=4, column=0, pady=(5, 5))
        right_answer = Label(frame,
                             text=GameInfoDict['questions'][q]['true'],
                             bg="white",
                             fg='black',
                             font=("Comic Sans MS", 10))
        right_answer.grid(row=5, column=0, pady=(10, 10))
    else:  # the last question
        del answers[0]
        # get grade
        grade = gL.end(Gamer_name.get(), answers, GameInfoDict, 1)
        list = frame.grid_slaves()
        for l in list:
            l.destroy()
        background_label = Label(window, image=fileBackground2)
        background_label.place(x=0, y=0, relwidth=1, relheight=1)
        frame = Frame(window, bg="white")
        frame.grid(row=1, column=1)
        frame.grid_columnconfigure(0, weight=1)
        frame.grid_rowconfigure(0, weight=1)
        message1 = Label(frame,
                         text='you grade: ' + str(grade),
                         fg='black',
                         bg="white",
                         font=("Comic Sans MS", 16))
        message1.grid(row=0, column=0, pady=(5, 5))

        bottonEasy = Button(
            frame,
            text='Back to menu',
            bg="#10c716",
            fg="white",
            font=("Comic Sans MS", 16),
            command=lambda: start(window, Gamer_name, fileBackground2))
        bottonEasy.grid(row=1, column=0, pady=(5, 5))