-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain1.py
More file actions
106 lines (76 loc) · 2.79 KB
/
main1.py
File metadata and controls
106 lines (76 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import tkinter as tk
from tkinter import messagebox, ttk
from ttkbootstrap import Style
from quiz_data import quiz_data
def show_question():
global current_question
question = quiz_data[current_question]
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="", foreground="white")
next_btn.config(state="disabled")
def check_answer(choice):
global score
question = quiz_data[current_question]
selected = choice_btns[choice].cget("text")
if selected == question["answer"]:
score += 1
score_label.config(text=f"Score: {score}/{len(quiz_data)}")
feedback_label.config(text="Correct!", foreground="lightgreen")
else:
feedback_label.config(text="Incorrect!", foreground="red")
for btn in choice_btns:
btn.config(state="disabled")
next_btn.config(state="normal")
def next_question():
global current_question
current_question += 1
if current_question < len(quiz_data):
show_question()
else:
messagebox.showinfo("Quiz Completed",
f"Quiz Completed!\nFinal Score: {score}/{len(quiz_data)}")
root.destroy()
root = tk.Tk()
root.title("Quiz App")
root.geometry("650x550")
style = Style(theme="cyborg")
root.configure(bg="#1a1a1a")
style.configure("Question.TLabel",
font=("Helvetica", 22, "bold"),
foreground="#00eaff",
background="#1a1a1a",
padding=20)
style.configure("Score.TLabel",
font=("Helvetica", 16, "bold"),
foreground="#ffdd00",
background="#1a1a1a",
padding=10)
style.configure("Feedback.TLabel",
font=("Helvetica", 18, "bold"),
background="#1a1a1a",
padding=10)
qs_label = ttk.Label(root, wraplength=600, anchor="center", style="Question.TLabel")
qs_label.pack(pady=10)
choice_btns = []
for i in range(4):
btn = ttk.Button(
root,
command=lambda i=i: check_answer(i),
bootstyle="info"
)
btn.pack(pady=8, padx=40, fill="x")
choice_btns.append(btn)
feedback_label = ttk.Label(root, text="", anchor="center", style="Feedback.TLabel")
feedback_label.pack(pady=15)
score = 0
score_label = ttk.Label(root, text=f"Score: {score}/{len(quiz_data)}",
anchor="center", style="Score.TLabel")
score_label.pack(pady=10)
next_btn = ttk.Button(root, text="Next", bootstyle="success", command=next_question, state="disabled")
next_btn.pack(pady=10)
current_question = 0
show_question()
root.mainloop()