Python Parking Lot Management System – Project Structure and Core Code
This article presents a Python parking‑lot management application, detailing its directory layout, explaining each module such as button handling, OCR utilities, and time processing, and showcasing the main pygame‑based code that renders parking information and visualizes remaining spaces.
Recently I revisited a small Python project I had practiced earlier, documenting its structure and core implementation.
Project Structure
datefile folder: stores the vehicle information Excel file.
file folder: contains image assets – ic_launcher.jpg (window icon), income.png (bar chart for revenue), key.txt (Baidu image‑recognition API key), test.jpg (camera‑captured image).
venv folder: virtual environment with required Python packages.
btn.py : button module.
main.py : main program file.
ocrutil.py : license‑plate recognition module.
timeutil.py : time‑handling utilities.
Main Code
<code># 车位文字
def text1(screen):
# 剩余车位
k = Total - carn
if k < 10:
# 剩余车位
sk = '0' + str(k)
else:
sk = str(k)
# 使用系统字体
xtfont = pygame.font.SysFont('SimHei', 20)
# 重新开始按钮
textstart = xtfont.render('共有车位:' + str(Total) + ' 剩余车位:' + sk, True, WHITE)
# 获取文字图像位置
text_rect = textstart.get_rect()
# 设置文字图像中心点
text_rect.centerx = 820
text_rect.centery = 30
# 绘制内容
screen.blit(textstart, text_rect)
# 停车场信息表头
def text2(screen):
xtfont = pygame.font.SysFont('SimHei', 15)
textstart = xtfont.render(' 车号 时间 ', True, WHITE)
text_rect = textstart.get_rect()
text_rect.centerx = 820
text_rect.centery = 70
screen.blit(textstart, text_rect)
pass
# 停车场车辆信息
def text3(screen):
xtfont = pygame.font.SysFont('SimHei', 12)
cars = pi_table[['carnumber','date','state']].values
if len(cars) > 10:
cars = pd.read_excel(path + '停车场车辆表.xlsx', skiprows=len(cars) - 10, sheet_name='data').values
n = 0
for car in cars:
n += 1
textstart = xtfont.render(str(car[0]) + ' ' + str(car[1]), True, WHITE)
text_rect = textstart.get_rect()
text_rect.centerx = 820
text_rect.centery = 70 + 20 * n
screen.blit(textstart, text_rect)
pass</code>Result
The application displays the total number of parking spaces, remaining slots, and a scrolling list of vehicle numbers with entry times, updating dynamically as cars enter or leave.
Below is a screenshot of the final UI:
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.