Advertisement

Responsive Advertisement

Application Programming Interface API

Sangram panda blogg

Instagram

source code

              
    
from tkinter import * THEME_COLOR = "#375362" FONT = ("Arial", 16, "italic") class QuizeInterface: def __init__(self, quize_brain: QuizBrain) -> None: self.quiz = quize_brain self.window = Tk() self.window.title("Quicquize") self.window.config(padx=15, pady=15, bg=THEME_COLOR) # lable self.question_label = Label( text="Question:1", fg="white", bg=THEME_COLOR, font=("Arial", 12, "bold")) self.question_label.grid(column=0, row=0) self.score_label = Label( text="Score:0", fg="white", bg=THEME_COLOR, font=("Arial", 12, "bold")) self.score_label.grid(column=1, row=0) # canvas/ text area self.canvas = Canvas(width=300, height=250, bg="white") self.question_text = self.canvas.create_text( 150, 125, width=270, text="Some queation", fill=THEME_COLOR, font=FONT ) self.canvas.grid(column=0, row=2, columnspan=2, pady=50) # photoimg self.right_img = PhotoImage(file="TK-GUI\\new quize\\images\\true.png") self.wrong_img = PhotoImage( file="TK-GUI\\new quize\\images\\false.png") # buttons self.right_btn = Button(image=self.right_img, highlightthickness=0, command=self.it_true) self.right_btn.grid(column=1, row=4) self.wrong_btn = Button(image=self.wrong_img, highlightthickness=0, command=self.it_false) self.wrong_btn.grid(column=0, row=4) self.next_q() self.window.mainloop() def next_q(self): self.canvas.config(bg="white") self.question_label.config(text=f"Question:{self.quiz.question_number+1}") if self.quiz.still_has_questions(): self.score_label.config(text=f"Score: {self.quiz.score}") q_text = self.quiz.next_question() self.canvas.itemconfig(self.question_text, text=q_text) else: self.canvas.itemconfig(self.question_text, text="You've reached the end of the quiz.") self.right_btn.config(state="disabled") self.wrong_btn.config(state="disabled") def it_true(self): self.give_feesback(self.quiz.check_answer("True")) def it_false(self): is_right = self.quiz.check_answer("False") self.give_feesback(is_right) def give_feesback(self, is_right): if is_right: self.canvas.config(bg="green") else: self.canvas.config(bg="red") self.window.after(1000,self.next_q)

Post a Comment

1 Comments