Python Seat Reservation System with PySide2 GUI and Command‑Line Tools
This article presents a complete Python‑based seat reservation system that uses PySide2 to build an interactive graphical interface for selecting and booking seats, stores configuration and occupancy data in JSON files, and provides command‑line utilities for checking in, checking out, making reservations, and handling temporary leaves, illustrating both front‑end UI design and back‑end logic in a single project.
The tutorial walks through building a self‑study room seat reservation application in Python. Required libraries (PySide2, datetime, json, argparse) are listed, and configuration files seatInf.json and occupied.json define table positions, sizes, styles, and current occupancy.
Two command‑line scripts are provided:
slotCard_in.py -i="<student_id>" – validates a campus card and displays the booked seat.
slotCard_out.py -i="<student_id>" – records a temporary leave or frees the seat.
cmd_order.py – shows available seats, accepts -i , -n , and -s arguments to create a reservation, and prints success or error messages.
The main GUI is implemented in orderSystem.py . A Window_main class creates the main window, loads the JSON data, and builds the layout with sections for title, information entry, seat selection, and a scrollable map. Seats are rendered as QPushButton widgets whose style changes based on occupancy, and clicking a seat updates the current selection.
When the user clicks the "预约" (book) button, the program checks for duplicate bookings, records the current timestamp, prints the reservation details, displays a confirmation window ( orderDataDisplay.py ), and updates the occupancy JSON.
The confirmation window ( Window_disp ) shows the student's name, ID, booking time, and seat ID, along with important notices. It also provides "暂离" (temporary leave) and "离开\取消" (leave/cancel) buttons that invoke tempLeave and leave methods to update the occupancy state.
Overall, the article demonstrates how to combine a PySide2 graphical front‑end with JSON‑based data storage and command‑line utilities to create a functional desktop reservation system.
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.