0% found this document useful (0 votes)
2 views

Cs Jai Shree

The document outlines a Python GUI project called the Olympiad Module, developed using Tkinter for organizing quiz competitions. It includes features for teachers to manage questions and view results, as well as for students to take quizzes, with data stored in binary files using the pickle module. The project aims to apply programming knowledge in real-world situations and emphasizes object-oriented programming principles.

Uploaded by

ballujaishree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Cs Jai Shree

The document outlines a Python GUI project called the Olympiad Module, developed using Tkinter for organizing quiz competitions. It includes features for teachers to manage questions and view results, as well as for students to take quizzes, with data stored in binary files using the pickle module. The project aims to apply programming knowledge in real-world situations and emphasizes object-oriented programming principles.

Uploaded by

ballujaishree
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

PYTHON GUI PROJECT

OLYMPIAD MODULE

DONE BY :

JAI sHREE.P
INDEX
1. ABOUT PYTHON
2. ABOUT TKINTER
3. ABOUT FILE HANDLING
4. PROJECT DESCRIPTION
5. SOFTWARE SPECIFICATION
6. SOURCE CODE
7. SAMPLE OUTPUT
8. CONCLUSION
9. INSTALLATION PROCEDURE
10. BIBLIOGRAPHY

1
ABOUT PYTHON:
Python programming language was developed by Guido Van Rossum in February 1991.
Python is based on or influenced with two programming languages:

➢ ABC language, a teaching language created as a replacement of BASIC, and

➢ Modula-3

Python is an interpreted object-oriented, high-level programming language with dynamic


semantics. Its high-level built in data structures, combined with dynamic typing and dynamic
binding, make it very attractive for Rapid Application Development, as well as for use as a
scripting or glue language to connect existing components together. Python's simple, easy to
learn syntax emphasizes readability and therefore reduces the cost of program maintenance.
Python supports modules and packages, which encourages program modularity and code reuse.
The Python interpreter and the extensive standard library are available in source or binary form
without charge for all major platforms, and can be freely distributed.

Often, programmers fall in love with Python because of the increased productivity it provides.
Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging
Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead,
when the interpreter discovers an error, it raises an exception. When the program doesn't catch
the exception, the interpreter prints a stack trace. A source level debugger allows inspection of
local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping
through the code a line at a time, and so on. The debugger is written in Python itself, testifying
to Python's introspective power.

2
ABOUT TKINTER:
Tkinter is a python program binding to the Tk GUI toolkit. It is the standard Python interface
to the Tk GUI toolkit, and is Python’s de facto standard GUI.Tkinter is included with standard
Linux, Microsoft Windows and Mac OS X installs of Python.Tk is a, cross-platform widget
toolkit that provides a library of basic elements of GUI widgets for building a graphical user
interface (GUI) in many programming languages.

The name Tkinter comes from Tk interface. Tkinter was written by Steen Lumholt and Guido
Van Rossum, then later revised by Fredrik Lundh. Like Tcl, Tk support Unicode within the
Basic Multilingual Plane, but it has not yet been extended to handle the current extended full
Unicode (e.g., UTF-16 from UCS-2 that Tk supports).

Tk has the following characteristics:

Platform-independent: Like Tcl, Tk is interpreted. It has been ported to multiple platforms


and can easily run on all of them without modification.

Customizable: Almost all the features of a widget in Tk are customizable through options
during the creation of the widget or later on through the configure command.

Configurable: Many of the options can be stored in an option database, making it very easy to
parameterize the look of an application (such as the color scheme). This also means that storing
the application-specific options is only a matter of saving the option add commands and
executing them on loading the application.

3
FEATURES OF TK:
Tk provides various widgets. Basic widgets are embedded into toplevel widgets, which in turn
are usually hosted by the operating system in floating windows that can be moved around on
the screen.

Basic widgets

Language bindings:
• A library written in one programming language may be used in another language if
bindings are written; TK is integrated with the TCL language. Various other languages
have bindings for TK, a partial list of which is on the TK website. Bindings exist for
additional languages which might not be listed, including Ada (called TASH),Haskell
(called HTK), Perl, Python (called TK inter), Ruby, Rex, and Common Lisp.

• There are several ways to use TK from Perl: the TCL::TK and TKX, Perl, both of which
use TCL as a bridge to access TK, and Perl/TK, which provides native Perl access to
TK structures. The Python binding uses TCL as a bridge to TK.

4
ABOUT FILE HANDLING:
File handling is an integral part of programming. File handling in Python is simplified with
built-in methods, which include creating, opening, and closing files.

While files are open, Python additionally allows performing various file operations, such as
reading, writing, and appending information.

TYPES OF FILES:
Text File:
Computers store every file as a collection of 0s and 1s i.e., in binary form. Therefore, every file
is basically just a series of bytes stored one after the other. There are mainly two types of data
files — text file and binary file. A text file consists of human readable characters, which can be
opened by any text editor. On the other hand, binary files are made up of non-human readable
characters and symbols, which require specific programs to access its contents. 2.2.1 Text file
A text file can be understood as a sequence of characters consisting of alphabets, numbers and
other special symbols. Files with extensions like .txt, .py, .csv, etc. are some examples of text
files. When we open a text file using a text editor (e.g., Notepad), we see several lines of text.
However, the file contents are not stored in such a way internally. Rather, they are stored in
sequence of bytes consisting of 0s and 1s. In ASCII, UNICODE or any other encoding scheme,
the value of each character of the text file is stored as bytes. So, while opening a text file, the
text editor translates each ASCII value and shows us the equivalent character that is readable
by the human being. For example, the ASCII value 65 (binary equivalent 1000001) will be
displayed by a text editor as the letter ‘A’ since the number 65 in
ASCII character set represents ‘A’. Each line of a text file is terminated by a special character,
called the End of Line (EOL). For example, the default EOL character in Python is the newline
(\n). However, other characters can be used to indicate EOL. When a text editor or a program
interpreter encounters the ASCII equivalent of the EOL character, it displays the remaining file
contents starting from a new line. Contents in a text file are usually separated by whitespace,
but comma (,) and tab (\t) are also commonly used to separate values in a text file.

5
Binary File:
A binary file is a file whose content is in a binary format consisting of a series of sequential
bytes, each of which is eight bits in length. The content must be interpreted by a program or a
hardware processor that understands in advance exactly how that content is formatted and how
to read the data. Binary files include a wide range of file types, including executables, libraries,
graphics, databases, archives and many others. Electronic files are typically categorized as
either binary files or text files. It could be argued that text files are also a type of binary file
because, like any electronic file, they're made up of sequences of bytes. However, the two are
generally considered to be different types.

Text files are in a human-readable format and typically adhere to specific character sets, such
as Unicode.

The man feature of Binary in Olympiad module is :

➢ Saving the data into binary files


Questions are saved in a binary file named questions.pkl
Results are saved in a binary file named results.pkl.
➢ Loading the data into binary files

• If the questions.pkl file exists, it loads the questions list.


• If the results.pkl file exists, it loads the results list.

➢ Pickle refers to the process of converting Python objects (like lists, dictionaries, etc.)
into a byte stream that can be saved to a file. .pkl is just the file extension for files that
store serialized Python objects.

CSV File:
A CSV file (Comma Separated Values file) is a type of plain text file that uses specific
structuring to arrange tabular data. Because it’s a plain text file, it can contain only actual text
data—in other words, printable ASCII or Unicode characters.

The structure of a CSV file is given away by its name. Normally, CSV files use a comma to
separate each specific data value.

6
PROJECT DESCRIPTION:
Objective:
The objective of this project is to let the students apply the programming knowledge into a

realworld situation/problem and exposed the students how programming skills helps in

developing a good software.

1. Write programs utilizing modern software tools.

2. Apply object oriented programming principles effectively when developing small to

medium sized projects.

3. Write effective procedural code to solve small to medium sized problems.

4. Students will demonstrate a breadth of knowledge in computer science, as exemplified

in the areas of systems, theory and software development.

5. Students will demonstrate ability to conduct a research or applied Computer Science

project, requiring writing and presentation skills which exemplify scholarly style in

computer science.

Description:
The Olympiad Module is a Python-based application developed using the `Tkinter` library for

creating a graphical user interface (GUI). The module is designed for organizing an

Olympiadstyle quiz competition where students can take quizzes, and teachers can manage

questions and view results. The application supports different types of questions, including

multiple-choice, fill-in-the-blank, and true/false questions. The data, such as questions and

results, are saved and loaded from binary files using the `pickle` module.

7
Features:
1. Teacher's Dashboard:
- Teachers can access the dashboard after entering a valid password.
- Teachers can add new questions in different formats: Multiple-choice (MCQ), Fill-in-
theBlank (FIB), and True/False (T/F).
- Teachers can view the results of student attempts.

2. Student Interface:
- Students can take the quiz after entering their name.
- Students answer questions, and their scores are tracked.
- Once all questions are answered, the student's final score is displayed.

3. Data Storage:
- Questions and results are saved in binary files (`questions.pkl` and `results.pkl`), using
the `pickle` module.
- The data is loaded when the application starts and saved back to the files after each
modification or quiz completion.

How It Works:
- Upon launching the application, the main menu is displayed, offering options for
teachers and students.
- Teachers can manage the quiz by adding questions or viewing results, while students
can attempt the quiz after entering their name.
- Questions are loaded from the saved file at the start of the quiz, and the student's
answers are evaluated in real time. The score is updated and displayed at the end of the quiz.

8
Usage of data
1. Loading Data:
- On startup, the application checks for existing `questions.pkl` and `results.pkl` files. If they
exist, the data is loaded into memory; otherwise, empty data structures are initialized.

2. Saving Data:
- Every time a question is added or a student's results are updated, the corresponding data is
serialized and saved back to the respective `.pkl` files.

3. Managing Quiz:
- The quiz is dynamic, with the application displaying questions and recording answers.
The flow proceeds through the questions in sequence, and once all questions are answered, the
student's score is recorded and displayed.

4.File Format (Pickle):


- The `questions.pkl` and `results.pkl` files are binary files that store serialized Python
objects using the `pickle` module.
- These files are not human-readable, as they store the data in a binary format optimized
for Python's internal object structure.

MODULES:
The important modules used in the project are as follows:

• Login page
• Teachers dashboard
• Student interface
• Add questions
• Result viewing
• Score viewing

9
SOFTWARE SPECIFICATION:
Operating System : Windows10
Platform : Python IDLE 3.12
Language : Python

SOURCE CODE:
import tkinter as tk
from tkinter import simpledialog, messagebox
import pickle import os

class OlympiadModule:
def __init__(self, root):
self.root = root
self.root.title("Olympiad Module")

self.questions_file = "questions.pkl"
self.results_file = "results.pkl"
self.password = "123" # Password for teacher access

self.load_data()
self.main_menu()

def load_data(self):
if os.path.exists(self.questions_file):
with open(self.questions_file, 'rb') as file:
self.questions = pickle.load(file)
else:
self.questions = []

10
if os.path.exists(self.results_file):
with open(self.results_file, 'rb') as file:
self.results = pickle.load(file)
else:
self.results = []
def save_data(self): with
open(self.questions_file, 'wb') as file:
pickle.dump(self.questions, file)

with open(self.results_file, 'wb') as file:


pickle.dump(self.results, file)

def main_menu(self): for widget in


self.root.winfo_children():
widget.destroy()

# Set the background color for the main window


self.root.config(bg='lavender')

title = tk.Label(self.root, text="Olympiad Module", font=("Helvetica", 56), pady=20,


bg='lavender')
title.pack(pady=(100,50))

teacher_btn = tk.Button(self.root, text="Teacher", command=self.prompt_password,


width=50, height=5, bg='lightblue') teacher_btn.pack(pady=20)

student_btn = tk.Button(self.root, text="Student", command=self.student_menu,


width=50, height=5, bg='lightgreen') student_btn.pack(pady=20)

def prompt_password(self):
password = simpledialog.askstring("Password", "Enter teacher password:", show="*")
if password == self.password:

11
self.teacher_menu()
else:
messagebox.showerror("Error", "Incorrect password!")
def teacher_menu(self): for widget in
self.root.winfo_children():
widget.destroy()

# Set the background color for the teacher's menu


self.root.config(bg='lightgreen')

title = tk.Label(self.root, text="Teacher's Dashboard", font=("Helvetica", 36), pady=20,


bg='lightgreen')
title.pack(pady=(100,50))

add_question_btn = tk.Button(self.root, text="Add Question",


command=self.choose_question_type, width=50, height=5, bg='lightblue')
add_question_btn.pack(pady=20)

view_results_btn = tk.Button(self.root, text="View Results", command=self.view_results,


width=50, height=5, bg='pink') view_results_btn.pack(pady=20)

back_btn = tk.Button(self.root, text="Back", command=self.main_menu, width=50,


height=5, bg='lightcoral') back_btn.pack(pady=20)

def choose_question_type(self):
question_type = simpledialog.askstring("Question Type", "Enter question type (mcq /
fib / t/f):") if question_type == "mcq":
self.add_question()
elif question_type == "fib":
self.add_fill_in_the_blank_question()
elif question_type == "t/f":
self.add_true_false_question()
else:

12
messagebox.showerror("Error", "Invalid
question type!")

def add_question(self):
question = simpledialog.askstring("Input", "Enter the question:")
if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return

choices = []
for i in range(4):
choice = simpledialog.askstring("Input", f"Enter choice {i+1}:")
if not choice:
messagebox.showerror("Error", "All choices must be filled!")
return
choices.append(choice)

correct_answer = simpledialog.askstring("Input", "Enter the correct answer:")


if correct_answer and correct_answer in choices:
self.questions.append({"question": question, "type": "multiple-choice", "choices":
choices, "correct_answer": correct_answer}) self.save_data()
messagebox.showinfo("Success", "Question added successfully!")
else:
messagebox.showerror("Error", "Correct answer must be one of the choices!")

def add_fill_in_the_blank_question(self):
question = simpledialog.askstring("Input", "Enter the question with a blank (use _ for
blank):") if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return

13
answer = simpledialog.askstring("Input", "Enter the correct answer:")
if not answer:
messagebox.showerror("Error", "Answer cannot be empty!")
return

self.questions.append({"question": question, "type": "fill-in-the-blanks",


"correct_answer": answer})
self.save_data()
messagebox.showinfo("Success", "Fill-in-the-blank question added successfully!")

def add_true_false_question(self):
question = simpledialog.askstring("Input", "Enter the true/false question:")
if not question:
messagebox.showerror("Error", "Question cannot be empty!")
return

correct_answer = simpledialog.askstring("Input", "Enter the correct answer


(true/false):") if correct_answer.lower() in
['true', 'false']:
self.questions.append({"question": question, "type": "true/false", "correct_answer":
correct_answer.lower()}) self.save_data()
messagebox.showinfo("Success", "True/False question added successfully!")
else:
messagebox.showerror("Error", "Correct answer must be 'true' or 'false'!")

def view_results(self): for widget in


self.root.winfo_children():
widget.destroy()

# Set the background color for the results view


self.root.config(bg='lightgreen')

14
title = tk.Label(self.root, text="Results", font=("Helvetica", 16), pady=20,
bg='lightgreen') title.pack()

for result in self.results:


result_label = tk.Label(self.root, text=f"{result['name']}: {result['score']}",
font=("Helvetica", 12), bg='lavender') result_label.pack(pady=5)

back_btn = tk.Button(self.root, text="Back", command=self.teacher_menu, width=30,


height=2, bg='lightcoral') back_btn.pack(pady=10)

def student_menu(self): for widget in


self.root.winfo_children():
widget.destroy()

# Set the background color for the student menu


self.root.config(bg='cyan')

self.student_name = simpledialog.askstring("Input", "Enter your name:")


if not self.student_name:
self.main_menu()
return

self.current_question_index = 0
self.score = 0 self.show_question()

def show_question(self): for widget


in self.root.winfo_children():
widget.destroy()

# Set the background color for the question view


self.root.config(bg='lightblue')

15
if self.current_question_index >= len(self.questions):
self.finish_quiz()
return

question_data = self.questions[self.current_question_index]
question_label = tk.Label(self.root, text=question_data["question"], font=("Helvetica",
14), pady=20, bg='lightblue')
question_label.pack()

if question_data["type"] == "multiple-choice":
self.selected_answer = tk.StringVar()
for choice in question_data["choices"]:
choice_btn = tk.Radiobutton(self.root, text=choice, variable=self.selected_answer,
value=choice, font=("Helvetica", 12), bg='lightblue') choice_btn.pack(anchor='w')

submit_btn = tk.Button(self.root, text="Submit", command=self.submit_answer,


width=30, height=2, bg='lightgreen') submit_btn.pack(pady=20)

elif question_data["type"] == "fill-in-the-blanks":


self.answer_entry = tk.Entry(self.root, font=("Helvetica", 12))
self.answer_entry.pack(pady=10)

submit_btn = tk.Button(self.root, text="Submit",


command=self.submit_fill_in_the_blank_answer, width=30, height=2, bg='lightgreen')
submit_btn.pack(pady=20)

elif question_data["type"] == "true/false":


self.selected_answer = tk.StringVar()
true_btn = tk.Radiobutton(self.root, text="True", variable=self.selected_answer,
value="true", font=("Helvetica", 12), bg='lightblue') true_btn.pack(anchor='w')

16
false_btn = tk.Radiobutton(self.root, text="False", variable=self.selected_answer,
value="false", font=("Helvetica", 12), bg='lightblue') false_btn.pack(anchor='w')

submit_btn = tk.Button(self.root, text="Submit", command=self.submit_answer,


width=30, height=2, bg='lightgreen') submit_btn.pack(pady=20)

def submit_answer(self):
selected = self.selected_answer.get()
if selected:
question_data = self.questions[self.current_question_index]
correct_answer = question_data["correct_answer"]

# Debugging the answers


print(f"Selected answer: {selected}, Correct answer: {correct_answer}")

# Case-insensitive comparison if
selected.lower() == correct_answer.lower():
self.score += 1
print(f"Score updated: {self.score}") # Debugging the score

self.current_question_index += 1
self.show_question() else:
messagebox.showwarning("Warning", "Please select an answer!")
def submit_fill_in_the_blank_answer(self):
answer = self.answer_entry.get().strip() if
answer:
correct_answer = self.questions[self.current_question_index]["correct_answer"]

# Debugging the answers


print(f"Entered answer: {answer}, Correct answer: {correct_answer}")

if answer.lower() == correct_answer.lower():

17
self.score += 1
print(f"Score updated: {self.score}") # Debugging the score

self.current_question_index += 1
self.show_question() else:
messagebox.showwarning("Warning", "Please enter an answer!")

def finish_quiz(self): self.results.append({"name":


self.student_name, "score": self.score}) self.save_data()
print(f"Final score for {self.student_name}: {self.score}") # Debugging the final score
messagebox.showinfo("Olympiad Completed", f"Your score: {self.score}")

self.main_menu()

if __name__ == "__main__":
root = tk.Tk()
app = OlympiadModule(root)
root.mainloop()

18
SAMPLE OUTPUT:
HOME PAGE:

19
TEACHER’S DASHBOARD:

20
21
22
23
24
25
26
27
STUDENT INTERFACE:

28
29
30
VIEWING RESULT:

31
VIEWING QUESTION AND RESULT IN
BINARY FILE:

32
VIEWING ANSWERS OF STUDENT IN
PYTHON SHELL:

33
CONCLUSION:
“Olympiad module in Python is a great asset for accessing and manipulating data directly into

your Python program using tkinter. Unlike other programming languages, python is

uncomplicated & pretty straightforward and as already said, can help you save a lot of time.

With that said, one can try exploring a few more operations and methods associated with

Olympiad module to make their tasks more efficient and productive. Python is pretty easy

because most of the basic operations just take a single line of code to do the job.

The Olympiad Module is a comprehensive and user-friendly Python application designed for

educational purposes. It allows teachers to efficiently manage quizzes by adding various types

of questions, including multiple-choice, fill-in-the-blank, and true/false, while also enabling

students to participate in quizzes and track their progress. The use of `Tkinter` ensures an

intuitive graphical interface, providing smooth navigation and interaction for both teachers and

students. Data is stored in binary files using the `pickle` module, allowing easy saving and

retrieval of quiz questions and results.

This design facilitates a seamless experience, with teachers having full control over the quiz

content and the ability to view student results. Students, on the other hand, can take the quizzes,

have their answers evaluated in real-time, and receive instant feedback with their final score.

The system is structured to be scalable and flexible, with the potential for future enhancements,

such as integrating more question types or supporting a larger number of users. While the

current implementation is ideal for local environments, transitioning to more secure and

scalable data storage solutions could further enhance the application's robustness in the future.

Overall, the Olympiad Module is an effective tool for conducting interactive quizzes in

educational settings.

34
INSTALLATION PROCEDURE:
Install Python from web

Open the source code

Run Olympiad Module.py file

Work on the software

35
BIBLIOGRAPHY:
1. Computer science With Python - Class XII By: Sumita Arora

2. Computer science With Python - Class XII By: Preeti Arora

3. Website:https://www.geeksforgeeks.org/python-quiz-project/

4. Website:https://codewithcurious.com/projects/quiz-using-python

5. https://stackoverflow.com

36

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy