Managing Academic Courses with Flask, MongoDB, Tkinter, and Docker

Posted by


In this tutorial, we will be creating an Academic Course Manager application using Flask, MongoDB, Tkinter, and Docker. This application will allow users to add, delete, and update courses, as well as view a list of all courses in the system.

Prerequisites:

  • Basic knowledge of Python and Flask
  • MongoDB installed on your machine
  • Docker installed on your machine

Step 1: Setting up the Flask application

  1. Create a new directory for your project and navigate to it.
  2. Create a new Python virtual environment using the following command:
    python -m venv venv
  3. Activate the virtual environment:
    source venv/bin/activate
  4. Install Flask and other required libraries:
    pip install Flask pymongo
  5. Create a new Python file called app.py and add the following code to set up a basic Flask application:
    
    from flask import Flask

app = Flask(name)

if name == ‘main‘:
app.run(debug=True)


Step 2: Setting up MongoDB
1. Install the MongoDB Python driver using the following command:

pip install pymongo

2. Start the MongoDB server on your machine using the following command:

mongod

3. Create a new Python file called `db.py` and add the following code to establish a connection to the MongoDB database:
```python
from pymongo import MongoClient

client = MongoClient('mongodb://localhost:27017/')
db = client['academic_course_manager']

Step 3: Creating the Tkinter GUI

  1. Create a new Python file called gui.py and add the following code to create a basic Tkinter GUI for the Academic Course Manager:
    
    import tkinter as Tkinter

root = Tkinter.Tk()
root.title("Academic Course Manager")

root.mainloop()


Step 4: Building the Docker container
1. Create a new file called `Dockerfile` in the project directory and add the following code to build a Docker container for the Flask application:

FROM python:3

COPY . /app
WORKDIR /app

RUN pip install -r requirements.txt

EXPOSE 5000
CMD ["python", "app.py"]

2. Create a new file called `requirements.txt` in the project directory and add the following dependencies:

Flask==2.0.1
pymongo==3.12.0

3. Build the Docker container using the following command:

docker build -t academic-course-manager .

4. Run the Docker container using the following command:

docker run -p 5000:5000 academic-course-manager



In this tutorial, we have created an Academic Course Manager application using Flask, MongoDB, Tkinter, and Docker. This application allows users to manage academic courses through a simple GUI. Feel free to customize and expand upon this project to suit your own needs.