import tkinter as tk
from tkinter import messagebox

root = tk.Tk()
root.title("Online Quiz")
root.geometry("400x400")

quiz = [
    ("Which language is used for ML?", ["Python", "HTML", "CSS", "Java"], 0),
    ("What does GUI stand for?", ["Graphical User Interaction", "Graphical User Interface", "Global User Internet", "General Unified Interface"], 1),
    ("Which is a Python framework?", ["Django", "React", "Spring", "Angular"], 0)
]

q = 0
score = 0
ans = tk.IntVar()

def load():
    question.config(text=quiz[q][0])
    ans.set(-1)
    for i in range(4):
        opts[i].config(text=quiz[q][1][i])

def next_q():
    global q, score
    if ans.get() == -1:
        messagebox.showwarning("Wait!", "Select an option!")
        return
    if ans.get() == quiz[q][2]: score += 1
    q += 1
    if q < len(quiz): load()
    else:
        messagebox.showinfo("Result", f"Score: {score}/{len(quiz)}")
        root.destroy()

tk.Label(root, text="🧠 Online Quiz", font=("Arial", 16, "bold")).pack(pady=10)
question = tk.Label(root, wraplength=300, justify="left")
question.pack(pady=10)
opts = [tk.Radiobutton(root, variable=ans, value=i) for i in range(4)]
for o in opts: o.pack(anchor="w", padx=60)
tk.Button(root, text="Next →", command=next_q, bg="navy", fg="white").pack(pady=20)

load()
root.mainloop()