import tkinter as tk
from tkinter import messagebox
class ChildRightsQuiz:
def init(self, root):
self.root = root
self.root.title("Child Rights Quiz")
self.root.geometry("800x500")
self.root.config(bg="#ffefd5") # Set background color
self.questions = [
{"question": "Which right ensure a child's protection from discrimination?",
"options": ["Right to non Discrimination", "Right to play", "Right to education"],
"correct_option": "Right to non Discrimination",
"explanation": ". Under the article 15 ,Children have the right to protection from abuse, neglect, exploitation and discrimination ."},
{"question": "According to children's rights, every child has the right to what basic necessity?",
"options": ["Education", "Food", "Toys"],
"correct_option": "Food",
"explanation": "The right to adequate nutrition is fundamental to a child's development and well-being."},
{"question": "What is the essence of right to education?",
"options": ["Right to skip school", "Right to quality Education", "Right to chose Homework"],
"correct_option": "Right to quality Education",
"explanation": "The Constitution (Eighty-sixth Amendment) Act, 2002 inserted Article 21-A in the Constitution of India to provide free and compulsory education of all children in the age group of six to fourteen years as a Fundamental Right in such a manner as the State may, by law, determine."},
{"question": "In the context of education, what does the right to 'inclusive education' mean for children?",
"options": ["Access to education for all children, regardless of their abilities or disabilities",
"Exclusion of certain children from education",
"Compulsory education for all children"],
"correct_option": "Access to education for all children, regardless of their abilities or disabilities",
"explanation": "Inclusive education ensures that all children, regardless of their abilities, have the right to quality education."},
# {"question": "Identify the right being depicted in the image.",
# "image_path": "right_to_play.png",
# "options": ["Right to Play", "Right to Health", "Right to Expression"],
# "correct_option": "Right to Play",
# "explanation": "Playing is essential for a child's physical and mental development."},
# {"question": "Identify the right being depicted in the image.",
# "image_path": "right_to_education.png",
# "options": ["Right to Play", "Right to Education", "Right to Expression"],
# "correct_option": "Right to Education",
# "explanation": "Education is a fundamental right that every child should have access to."},
# {"question": "Identify the right being depicted in the image.",
# "image_path": "right_to_protection.png",
# "options": ["Right to Protection", "Right to Participation", "Right to Expression"],
# "correct_option": "Right to Protection",
# "explanation": "Children have the right to be protected from harm and exploitation."},
{"question": "What is the right of children to express their views freely in all matters affecting them?",
"options": ["Freedom of Speech", "Right to Participation", "Right to Expression"],
"correct_option": "Right to Participation",
"explanation": "The right to participation ensures that children have the right to express their views in matters concerning them."},
]
self.current_question = 0
self.score = 0
self.create_widgets()
def create_widgets(self):
self.question_label = tk.Label(self.root, text="", font=("Arial", 14), bg="#ffefd5") # Set background color
self.question_label.pack(pady=20)
self.image_label = tk.Label(self.root, image=None, bg="#ffefd5")
self.image_label.pack(pady=20)
self.option_buttons = []
for i in range(3):
button = tk.Button(self.root, text="", font=("Arial", 12), command=lambda i=i: self.check_answer(i), bg="#d4a5a5") # Set button color
button.pack(pady=10)
self.option_buttons.append(button)
self.previous_button = tk.Button(self.root, text="Previous", font=("Arial", 12), command=self.previous_question, bg="#a5c4d4") # Set button color
self.previous_button.pack(pady=20)
self.next_question_button = tk.Button(self.root, text="Next Question", font=("Arial", 12), command=self.next_question, bg="#a5c4d4") # Set button color
self.next_question_button.pack(pady=20)
self.load_question()
def load_question(self):
question_info = self.questions[self.current_question]
self.question_label.config(text=question_info["question"])
if "image_path" in question_info:
image_path = question_info["image_path"]
photo = self.load_image(image_path)
self.image_label.config(image=photo)
self.image_label.image = photo
else:
self.image_label.config(image=None)
for i in range(3):
self.option_buttons[i].config(text=question_info["options"][i])
def check_answer(self, selected_option):
question_info = self.questions[self.current_question]
correct_option = question_info["correct_option"]
user_answer = question_info["options"][selected_option]
if user_answer == correct_option:
self.score += 1
self.option_buttons[selected_option].config(bg="#7ec8a3") # Set correct answer button color
messagebox.showinfo("Correct!", "Fantastic! Your answer is correct.")
else:
self.option_buttons[selected_option].config(bg="#ff6b6b") # Set selected answer button color
correct_option_index = question_info["options"].index(correct_option)
self.option_buttons[correct_option_index].config(bg="#7ec8a3") # Set correct answer button color
explanation = question_info.get("explanation", "No explanation available.")
messagebox.showerror("Incorrect!", f"Oops! Correct answer is: {correct_option}\n\n{explanation}")
def next_question(self):
if self.current_question < len(self.questions) - 1:
self.current_question += 1
for button in self.option_buttons:
button.config(bg="#d4a5a5") # Reset button color
self.load_question()
else:
self.show_score_card()
def previous_question(self):
if self.current_question > 0:
self.current_question -= 1
for button in self.option_buttons:
button.config(bg="#d4a5a5") # Reset button color
self.load_question()
def show_score_card(self):
self.question_label.config(text=f"Quiz Completed!\nYour Score: {self.score}/{len(self.questions)}", bg="#ffefd5") # Set background color
for button in self.option_buttons:
button.pack_forget()
self.previous_button.pack_forget()
self.next_question_button.pack_forget()
if self.score == len(self.questions):
tk.Label(self.root, text="Congratulations! You got all questions right!", font=("Arial", 12), bg="#ffefd5").pack(pady=20)
tk.Button(self.root, text="Exit", font=("Arial", 12), command=self.root.destroy, bg="#a5c4d4").pack(pady=20) # Set button color
def load_image(self, path):
image = tk.PhotoImage(file=path)
return image
if name == "main":
root = tk.Tk()
app = ChildRightsQuiz(root)
root.mainloop()
import tkinter as tk from tkinter import messagebox
class ChildRightsQuiz: def init(self, root): self.root = root self.root.title("Child Rights Quiz") self.root.geometry("800x500") self.root.config(bg="#ffefd5") # Set background color
if name == "main": root = tk.Tk() app = ChildRightsQuiz(root) root.mainloop()