DEV Community

Simran
Simran

Posted on • Edited on

Building a Quiz App with Python and Tkinter – Step-by-Step Guide

πŸ“ Introduction

Building a Quiz App using Python and Tkinter was an exciting journey! I wanted to create a project that not only strengthens my Python programming skills but also provides an interactive user experience. A quiz app is a great way to combine GUI development, database management, and logical programming into a single project.

🎯 Features

  • User Authentication: Admin and Player login integrated into the same window.
  • Question Database: Managed with MySQL to store questions dynamically.
  • Interactive UI: Tkinter-based graphical interface with smooth transitions.
  • Real-time Score Tracking: Displays correct/incorrect answers with a progress indicator.
  • Result Summary: Shows final score and performance analysis.

πŸ› οΈ Tech Stack

  • Python (Core language)
  • Tkinter (GUI framework)
  • MySQL (Database for storing questions & user data)

πŸ—„οΈ Database Setup

Before running the app, make sure to configure your MySQL database:
Step 1 : Create the database

CREATE DATABASE quiz_app;
Enter fullscreen mode Exit fullscreen mode

Step 2 : Create the tables

USE quiz_app;

CREATE TABLE table_name (
    column1 INT AUTO_INCREMENT PRIMARY KEY,
    column2 VARCHAR(50) NOT NULL,
    column3 BOOLEAN NOT NULL
);
Enter fullscreen mode Exit fullscreen mode

Step 3 :Configure Connection in database.py
Inside database.py, set up the MySQL connection with your local credentials:

  • host : usually localhost
  • user : your MySQL username
  • password: your MySQL password
  • database: quiz_app

Also, make sure to define and export conn, cursor, and mysql so they can be imported in other files.
πŸ› οΈ If you see ImportError: cannot import name 'conn' from 'database', it means the connection variables are either not defined or not properly exported in database.py.

πŸš€ How to Run

Step 1 Clone the repository:

   git clone https://github.com/SIMRAN-202/Tkinter-Quiz-App   
Enter fullscreen mode Exit fullscreen mode

Step 2 Install Dependencies:

   pip install mysql-connector-python
Enter fullscreen mode Exit fullscreen mode

Step 3 Run the Application:

   python main.py
Enter fullscreen mode Exit fullscreen mode

πŸ† Challenges Faced & Solutions

  • Issue: Handling database connectivity dynamically.
    • Solution: Used MySQL Connector with parameterized queries.
  • Issue: UI not updating correctly after answering a question.
    • Solution: Used Tkinter’s after() method to refresh UI state smoothly.
  • Issue: Managing different user roles (Admin & Player) in the same window.
    • Solution: Implemented a single login window with role-based access control.

πŸŽ‰ Accomplishments

  • Successfully built a fully functional quiz app with dynamic questions.
  • Implemented real-time score tracking and user-friendly UI.
  • Learned efficient database management and Tkinter best practices.

πŸ“Œ Future Improvements

  • Add multiple question types (MCQs, fill-in-the-blanks, etc.).
  • Implement a leaderboard for competitive play.
  • Integrate Django for a web-based version in the future.

🀝 Contributing

If you’d like to contribute, feel free to fork the repository and submit a pull request! πŸ™Œ

πŸ“ž Contact

πŸ“§ Email: kaursimrankaur2003@gmail.com
πŸ”— LinkedIn: https://www.linkedin.com/in/simran-ba0595315/


Built with πŸ’™ by Simran

Top comments (2)

Collapse
 
ibrahimsma profile image
ibrahim s m a • Edited

Add how to setup the database to connect locally, this is throwing error and unable to run the program.
from database import conn, cursor, mysql
ImportError: cannot import name 'conn' from 'database' (c:\Users\Downloads\learnings\Tkinter-Quiz-App\database.py)

Collapse
 
simran022 profile image
Simran

Hi! Thanks for checking out the project
The error means the database.py file doesn't have the conn and cursor setup.
I'll update the article to include proper database setup steps so it runs smoothly. Appreciate the feedback!