diff --git a/Desktop Application/Basic/Python/Quiz_Application/README.md b/Desktop Application/Basic/Python/Quiz_Application/README.md new file mode 100644 index 000000000..986dad087 --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/README.md @@ -0,0 +1,101 @@ +# Quiz Application + +

gif

+
+ + + +![](https://img.shields.io/badge/Programming_Language-Python-blue.svg) +![](https://img.shields.io/badge/Main_Tool_Used-Tkinter-orange.svg) +![](https://img.shields.io/badge/Support_Tool_Used-smtplib,requests-orange.svg) +![](https://img.shields.io/badge/Python_Version-3.12-blue.svg) +![](https://img.shields.io/badge/Application-Quiz-brown.svg) +![](https://img.shields.io/badge/APi_used-Trivia-red.svg) +![](https://img.shields.io/badge/Status-Complete-green.svg) + + +--- + +## Table of Contents +- [Introduction](#introduction) +- [Features](#features) +- [Installation](#installation) +- [Usage](#usage) +- [Project_Screenshots](#Project-Screenshots) +- [Project Structure](#project-structure) +- [Dependencies](#dependencies) +- [Contributor](#contributor) + +## Introduction +Welcome to the Trivia Quiz Application! This project is a fun and interactive quiz application that leverages a trivia API to fetch questions and provides a user-friendly interface using `tkinter`. It also integrates email functionality via `smtplib` to send quiz results. The project is built using Object-Oriented Programming (OOP) principles to ensure modularity and maintainability. + +## Features +- Fetch trivia questions from an API. +- Interactive GUI built with `tkinter`. +- Email quiz results using `smtplib`. +- OOP design for better code organization and extensibility. + +## Installation +To get a local copy up and running, follow these simple steps: + +1. **Install dependencies:** + ```sh + pip install -r requirements.txt + ``` + +## Usage +To start the application, run the following command: +```sh +python main.py +``` +A GUI window will open, allowing you to start the quiz, answer questions, and submit your results via email. + +## Project Screenshots +

gif

+ +
+

gif

+ + +## Project Structure +``` +quiz-app/ +│ +├── images/ # Contains images used in the GUI +│ ├── false.png +│ └── true.png +├── main.py # Entry point of the application +├── ui.py # Contains the Tkinter GUI class +├── quiz_brain.py # Contains logic of quiz +├── question_model.py # Contains Question class +├── data.py # Contains the api request +├── players.csv # Stores the user data in csv file +│ +└── requirements.txt # List of dependencies +``` + +## Dependencies +- `tkinter`: For the GUI. +- `smtplib`: For sending emails. +- `requests`: For making API requests. +- Trivia API: Used to fetch trivia questions (e.g., Open Trivia Database). + +You can install all dependencies using: +```sh +pip install -r requirements.txt +``` + +## Contributor + + + + + + + +
+ + Sahuf Shaikh +
+ Sahuf Shaikh
+
diff --git a/Desktop Application/Basic/Python/Quiz_Application/data.py b/Desktop Application/Basic/Python/Quiz_Application/data.py new file mode 100644 index 000000000..5a1e5a1e7 --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/data.py @@ -0,0 +1,10 @@ +import requests +parameters ={ + "amount":10, + "type":"boolean", + "category":18 +} +response = requests.get(url="https://opentdb.com/api.php",params=parameters) +response.raise_for_status() +data= response.json() +question_data = data['results'] diff --git a/Desktop Application/Basic/Python/Quiz_Application/images/false.png b/Desktop Application/Basic/Python/Quiz_Application/images/false.png new file mode 100644 index 000000000..904c76d8f Binary files /dev/null and b/Desktop Application/Basic/Python/Quiz_Application/images/false.png differ diff --git a/Desktop Application/Basic/Python/Quiz_Application/images/quiz.png b/Desktop Application/Basic/Python/Quiz_Application/images/quiz.png new file mode 100644 index 000000000..91aaca057 Binary files /dev/null and b/Desktop Application/Basic/Python/Quiz_Application/images/quiz.png differ diff --git a/Desktop Application/Basic/Python/Quiz_Application/images/quizlol.png b/Desktop Application/Basic/Python/Quiz_Application/images/quizlol.png new file mode 100644 index 000000000..e71319a6d Binary files /dev/null and b/Desktop Application/Basic/Python/Quiz_Application/images/quizlol.png differ diff --git a/Desktop Application/Basic/Python/Quiz_Application/images/right_and_wrong_answer.png b/Desktop Application/Basic/Python/Quiz_Application/images/right_and_wrong_answer.png new file mode 100644 index 000000000..23ca0ad7a Binary files /dev/null and b/Desktop Application/Basic/Python/Quiz_Application/images/right_and_wrong_answer.png differ diff --git a/Desktop Application/Basic/Python/Quiz_Application/images/true.png b/Desktop Application/Basic/Python/Quiz_Application/images/true.png new file mode 100644 index 000000000..79ca9a304 Binary files /dev/null and b/Desktop Application/Basic/Python/Quiz_Application/images/true.png differ diff --git a/Desktop Application/Basic/Python/Quiz_Application/main.py b/Desktop Application/Basic/Python/Quiz_Application/main.py new file mode 100644 index 000000000..515e20bc7 --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/main.py @@ -0,0 +1,29 @@ +import smtplib +from question_model import Question +from data import question_data +from quiz_brain import QuizBrain +from ui import QuizInterfaces +MY_EMAIL =" " #your email here +PASSWORD = " " #your password here +question_bank = [] +for question in question_data: + question_text = question["question"] + question_answer = question["correct_answer"] + new_question = Question(question_text, question_answer) + question_bank.append(new_question) + +quiz = QuizBrain(question_bank) +quiz_ui = QuizInterfaces(quiz) + +import csv +with open('players.csv', 'w', newline='') as file: + writer = csv.writer(file) + field = ["name", "email", "score"] + writer.writerow(field) + writer.writerow([quiz_ui.name,quiz_ui.email,quiz.score]) + +with smtplib.SMTP("smtp.gmail.com",587) as connection: + connection.starttls() + connection.login(user=MY_EMAIL,password=PASSWORD) + connection.sendmail(from_addr=MY_EMAIL,to_addrs=quiz_ui.email,msg=f"Subject: {quiz_ui.name}\n\n Congratulations You scored {quiz.score}/{quiz.question_number} .\n \n Thanks for taking part in the quiz") + print("Successfully sent the mail") \ No newline at end of file diff --git a/Desktop Application/Basic/Python/Quiz_Application/players.csv b/Desktop Application/Basic/Python/Quiz_Application/players.csv new file mode 100644 index 000000000..c9bbac77d --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/players.csv @@ -0,0 +1 @@ +name,email,score diff --git a/Desktop Application/Basic/Python/Quiz_Application/question_model.py b/Desktop Application/Basic/Python/Quiz_Application/question_model.py new file mode 100644 index 000000000..b3d63d36b --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/question_model.py @@ -0,0 +1,5 @@ +class Question: + + def __init__(self, q_text, q_answer): + self.text = q_text + self.answer = q_answer diff --git a/Desktop Application/Basic/Python/Quiz_Application/quiz_brain.py b/Desktop Application/Basic/Python/Quiz_Application/quiz_brain.py new file mode 100644 index 000000000..0c36a64f8 --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/quiz_brain.py @@ -0,0 +1,26 @@ +import html +class QuizBrain: + + def __init__(self, q_list): + self.question_number = 0 + self.score = 0 + self.question_list = q_list + self.current_question = None + + def still_has_questions(self): + return self.question_number < len(self.question_list) + + def next_question(self): + self.current_question = self.question_list[self.question_number] + self.question_number += 1 + q_text = html.unescape(self.current_question.text) + return f"{self.question_number}: {q_text}" + + def check_answer(self, user_answer): + correct_answer = self.current_question.answer + if user_answer.lower() == correct_answer.lower(): + self.score += 1 + return True + else: + return False + diff --git a/Desktop Application/Basic/Python/Quiz_Application/requirements.txt b/Desktop Application/Basic/Python/Quiz_Application/requirements.txt new file mode 100644 index 000000000..f2293605c --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/Desktop Application/Basic/Python/Quiz_Application/ui.py b/Desktop Application/Basic/Python/Quiz_Application/ui.py new file mode 100644 index 000000000..89faf750a --- /dev/null +++ b/Desktop Application/Basic/Python/Quiz_Application/ui.py @@ -0,0 +1,55 @@ +from tkinter import * +from quiz_brain import QuizBrain +THEME_COLOR = "#375362" +from tkinter.simpledialog import askstring +from tkinter.messagebox import showinfo +class QuizInterfaces: + def __init__(self,quiz_brain: QuizBrain): + self.quiz = quiz_brain + self.window = Tk() + self.name = askstring('Name', 'What is your name?') + self.email = askstring('email', 'Your email') + showinfo('Hello', f"{format(self.name)}, {format(self.email)}") + self.window.title("Quizler") + self.window.config(padx=20,pady=20,bg=THEME_COLOR) + self.label = Label(text=f"Player Name:{self.name}", bg=THEME_COLOR, foreground="white") + self.label.grid(row=0, column=0) + self.label = Label(text=f"Score:{self.quiz.score}",bg=THEME_COLOR,foreground="white") + self.label.grid(row=0,column=1) + + self.canvas = Canvas(highlightcolor="white",width=300,height=250) + self.question_text = self.canvas.create_text(150,120,text="wassup bruh",width=280,font=('Arial',20,'italic')) + self.canvas.grid(row=1,column=0,columnspan=2,pady=20,padx=20) + + + true = PhotoImage(file="images/true.png") + false= PhotoImage(file="images/false.png") + self.right = Button(image=true,highlightthickness=0,command=self.true_press) + self.right.grid(row=2,column=0) + self.wrong = Button(image=false,highlightthickness=0,command=self.false_press) + self.wrong.grid(row=2,column=1) + self.get_next_question() + self.window.mainloop() + + def get_next_question(self): + self.canvas.config(bg="white") + if self.quiz.still_has_questions(): + self.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 have reached the end") + self.right.config(state="disabled") + self.wrong.config(state="disabled") + def true_press(self): + self.give_feedback(self.quiz.check_answer("True")) + + def false_press(self): + self.give_feedback(self.quiz.check_answer("False")) + + def give_feedback(self,is_right): + if is_right: + self.canvas.config(bg="green") + else: + self.canvas.config(bg="red") + self.window.after(1000,self.get_next_question) \ No newline at end of file diff --git a/Desktop Application/README.md b/Desktop Application/README.md index 9517bbd10..75206e612 100644 --- a/Desktop Application/README.md +++ b/Desktop Application/README.md @@ -72,6 +72,7 @@ | 28. | [Live News App](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Live%20News%20App) | | 29. | [Screen Recorder](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Screen-Recorder) | | 30. | [PDF Utility Tool](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/PDF%20Utility%20Tool) | +| 31. | [Quiz_Application](https://github.com/Kushal997-das/Project-Guidance/tree/main/Desktop%20Application/Basic/Python/Quiz_Application) |
## Java 🚀