Python Tkinter Vaccine Management System Tutorial with MySQL Integration
This article walks readers through building a complete vaccine management desktop application using Python's Tkinter for the graphical interface and MySQL for data storage, covering UI design, database connection, user registration, login, CRUD operations for vaccine records, and query functionalities, all illustrated with full source code examples.
The article introduces a practical Python project that implements a vaccine management system with a graphical user interface built using tkinter and a MySQL backend for persistent storage.
Overall Structure : The UI consists of a main window with buttons for login, registration, and exiting, followed by a functional options window that provides access to adding, querying, modifying, and deleting vaccine-related data.
Database Connection :
def connect_DBS(self, database, content):
db = pymysql.connect(host="localhost", user="root", password="pwd", database=database)
cursor = db.cursor()
cursor.execute(content)
data = cursor.fetchone()
db.commit()
db.close()
return dataMain Interface (login, registration, and main window):
def main_window(self):
tk.Button(app, text='登录', command=self.login).place(x=260, y=200)
tk.Button(app, text='注册', command=self.register).place(x=260, y=240)
tk.Button(app, text='退出', command=self.quit_mainloop).place(x=260, y=280)Functional Options provide buttons to manage vaccine information, distribution, maintenance, and vaccination personnel, each opening a dedicated Toplevel window.
Adding Vaccine Information :
def add_vacc_info(self):
add_vacc_info = tk.Toplevel(app)
# Labels and entry fields for batch number, name, company, etc.
tk.Button(add_vacc_info, text='添加', command=add).place(x=400, y=360)
tk.Button(add_vacc_info, text='清空', command=clear).place(x=160, y=360)Similar forms are provided for adding vaccine distribution ( add_vaccine_distr_info), maintenance ( add_vaccine_maintenance_info), and vaccination personnel ( add_vaccination_person_info), each with corresponding add and clear functions that construct INSERT statements and execute them via connect_DBS.
Query Functions allow users to retrieve records by entering identifiers; the results are displayed in a tk.Text widget after executing SELECT statements.
Modify and Delete Operations are implemented with separate windows that first fetch existing data, allow editing in tk.Text fields, and then issue UPDATE or DELETE statements.
Database Schema (MySQL):
create table vaccine_info(
vaccine_num char(50) not null primary key,
vaccine_name char(50) not null,
company_name char(50) not null,
company_num char(50) not null,
size char(50),
buy_price char(50) not null,
pre_sale_price char(20) not null,
limit_up char(50) not null,
limit_down char(50) not null
);
... (additional tables user_info, vaccine_distr_info, vaccine_maintenance_info, vaccination_person_info) ...Overall, the tutorial demonstrates end‑to‑end development of a desktop CRUD application, illustrating how to combine Tkinter UI components with MySQL operations in Python.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
