In this article I will cover how to build a SQL (Structured Query Language) based book management system in Python with an integrated graphical user interface.

A few python libraries you will need to import for this program:

  • numpy
  • sqlite3
  • json
  • easygui
  • platform
  • fuzzywuzzy
  • glob

Now before I go any further let me give you a short introduction. You might be wondering…why easygui? Why not rather Tkinter or PyQt to craft the GUI? Well… about a year ago I could not print “hello world” in a python IDE, neither did I have a clue what an IDE is. Around the end of 2019 with no domain knowledge whatsoever I hopped on a Data Science boot camp and started to familiarize myself with the python programming language so I am very much inexperienced still.

When you build a program which is designed for an end-user, normally they would prefer not to operate it via a cli (command line) environment. Users want to press buttons that look nice and the program must preferably be intuitive and easy to navigate.

Due to my limited experience I stumbled upon the easygui library and I found that its quite easy to use. This will likely be one of my last posts on using easygui as I don’t want to stagnate on this library but I want to show people who have little experience how easy it is to build a GUI around a program with easygui. Without further ado lets begin:

The data we are going to use for this program is a .json file I compiled myself. Its quite sparse but it will do the job. Feel free to compile your own and use that if you wish, just make sure you keep the format the same. You can name it whatever you like. Take care to save the .py and .json file in the same location. Below is a quick view of the books.json file:

Image for post

books.json

The JSON keys are intended to be self-explanatory but lets quickly go through them:

id: book id (this can also be changed to ISBN for example)

Title: book title

Author: book author

Qty: book quantity

Right, now lets fire up the IDE and start by importing the above mentioned python libraries:

Image for post

The program consist out of 27 functions. When you run the program, only one function named ‘which_way()’ gets called. From there on depending on user input, alternate functions gets called from within other functions. I will not cover every single one of them here as a few share similarity however I will include them all in the source code.

Lets have a look at the first one:

Image for post

This function spawns the main menu of the book manager. As this program consist of functions only we declare some variables as global in order for them to be available when referred to from other functions.

For the sake of simplicity whilst testing the GUI, I set the login to ‘admin’ and password as ‘1234’ as seen above on lines 26/27. You change this as you wish. After saving login, password and initializing the ‘boolean’ variable as ‘True’ we define the easygui choicebox parameters which sets the display text and options.

User input(text(string) or choice the user clicks on) gets saved in the ‘fieldValues’ variable. If the user chooses to create a new database from a .json file upload, the boolean variable gets set to ‘False’ and login_window(boolean) function gets called.

Alternatively if the user chooses to continue where they left off from a previous session, they can load the existing _db file by choosing the ‘Continue on existing database’ option which will call on the login_window(boolean) function with the boolean variable set to True. If however the user presses cancel, the program terminates.

#sqlite #gui #data-science #python3 #python

Book Management System with Python & SQLite3
3.70 GEEK