Skip to content

Commit

Permalink
Merge pull request #1195 from sahuf2003/quiz_application
Browse files Browse the repository at this point in the history
QUIZ Desktop Application
  • Loading branch information
Kushal997-das authored Jun 19, 2024
2 parents 17a3624 + a859e32 commit 7e0f66a
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 0 deletions.
101 changes: 101 additions & 0 deletions Desktop Application/Basic/Python/Quiz_Application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Quiz Application

<p align="center"><img src="https://github.com/sahuf2003/QUIZ-GUI-/blob/main/images/quizlol.png" alt="gif" height="300px" width="550px" ok"/><br></p>
<br>



![](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
<p align="center"><img src="https://github.com/sahuf2003/QUIZ-GUI-/blob/main/images/quiz.png" alt="gif" height="300px" width="550px" ok"/><br></p>

<br>
<p align="center"><img src="https://github.com/sahuf2003/QUIZ-GUI-/blob/main/images/right_and_wrong_answer.png" alt="gif" height="300px" width="550px" ok"/><br></p>


## 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

<table>
<tr>
<td align="center">
<a href="https://github.com/sahuf2003" target="_black">
<img src="https://github.com/sahuf2003.png" width="150px;" alt="Sahuf Shaikh"/>
<br />
<sub><b>Sahuf Shaikh</b></sub></a>
</td>


</tr>
</table>
10 changes: 10 additions & 0 deletions Desktop Application/Basic/Python/Quiz_Application/data.py
Original file line number Diff line number Diff line change
@@ -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']
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions Desktop Application/Basic/Python/Quiz_Application/main.py
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name,email,score
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Question:

def __init__(self, q_text, q_answer):
self.text = q_text
self.answer = q_answer
26 changes: 26 additions & 0 deletions Desktop Application/Basic/Python/Quiz_Application/quiz_brain.py
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests
55 changes: 55 additions & 0 deletions Desktop Application/Basic/Python/Quiz_Application/ui.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions Desktop Application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
</br>

## Java 🚀
Expand Down

0 comments on commit 7e0f66a

Please sign in to comment.