#How well you know your computer #Running this will start the programm, startup time can be up to 10sec depending on the system #DOSENT WORK WITH ANYTHING ELSE EXCEPT WINDOWS import tkinter as tk #pip install tk from tkinter import * #pip install tk from tkinter import messagebox, ttk #pip install tk from ttkbootstrap import Style #pip install ttkbootstrap from nonni import Questions #Questions #GUI current_question = 0 def show_question(): question = Questions[current_question] #Shows a question and choices from Questions qs_label.config(text=question["question"]) choices = question["choices"] for i in range(4): choice_btns[i].config(text=choices[i], state="normal") feedback_label.config(text="") next_btn.config(state="disabled") #Next button disabled while no choices chosen def check_answer(choice): question = Questions[current_question] #Checks answer selected_choice = choice_btns[choice].cget("text") if selected_choice == question["answer"]: global score #If correct answer raise score by one score += 1 score_label.config(text="Score: {}/{}".format(score, len(Questions))) feedback_label.config(text="Correct!", foreground="green") else: #Shows feedback and score feedback_label.config(text="Incorrect!", foreground="red") for button in choice_btns: button.config(state="disabled") #Choice buttons are disabled after picking a next_btn.config(state="normal") #choice and next button unlocks def next_question(): global current_question #Shuffles to next guestion and dosent current_question +=1 #display the same question if current_question < len(Questions): #Show question if there are left any show_question() else: #If no questions remaining, show final score messagebox.showinfo("Quiz Completed", "Quiz Completed! Final score: {}/{}".format(score, len(Questions))) root.destroy() #Terminate after final score root = tk.Tk() root.title("How well you know your computer") #Window title root.geometry("667x800") #Initial resolution and same resolution as background style = Style(theme="flatly") #Sets button color theme style.configure("TLabel", font=("FreeSans", 25)) #Label font for questions style.configure("TButton", font=("Helvetica", 16)) #Button font for buttons root.resizable(False, False) #Makes window not resizable beacuse background image is not scalable background = PhotoImage(file="background.png") #Background image bg_label = ttk.Label(root, image=background) bg_label.place(x=0,y=0, relwidth=1, relheight=1) qs_label = ttk.Label( root, anchor="center", #Centerizes label wraplength=800, #Length for label characters per row padding=20, #Adds space around label background="#66a3ff" #Matches label background color to background image color ) qs_label.pack(pady=10) #More space choice_btns = [] for i in range(4): button = ttk.Button( root, command=lambda i=i: check_answer(i) ) button.pack(pady=5) #Verical space between choices choice_btns.append(button) feedback_label = ttk.Label( root, anchor="center", padding=5, font=("Helvetica", 35), background="#66a3ff" #Matches label background color to background image color ) feedback_label.pack(pady=10) score = 0 score_label = ttk.Label( #Score label centered with padding root, text="Score: 0/{}".format(len(Questions)), anchor="center", padding=10, background="#66a3ff" #Matches label background color to background image color ) score_label.pack(pady=10) next_btn = ttk.Button( #Next button disabled by default root, text="Next", command=next_question, state="disabled", padding=10 ) next_btn.pack(pady=10) show_question() #Start root.mainloop()