Python PyQt5 Personal Information Management GUI Tutorial
This article introduces a Python PyQt5 desktop application that manages personal information, detailing required modules, supported operations such as add, modify, delete, and query, and provides a complete source code example for building the GUI.
1. Modules Involved
datetime
os
random
sys
PyQt5
2. Running Effect
Supported functions:
Add information
Modify information
Delete information
Query information
File storage persists data across runs
3. Sample Source Code
<code># 创建字体对象,用来对要显示的文字进行设定
font = QtGui.QFont()
font.setFamily("黑体")
font.setPointSize(12)
# 姓名
label_name = QLabel(self)
label_name.setGeometry(40, 30, 54, 16)
label_name.setText("姓名:")
label_name.setFont(font)
self.line_edit_name = QLineEdit(self)
self.line_edit_name.setGeometry(90, 30, 141, 20)
# 性别
label_gender = QLabel(self)
label_gender.setGeometry(270, 30, 54, 16)
label_gender.setFont(font)
label_gender.setText("性别:")
self.line_edit_gender = QComboBox(self)
self.line_edit_gender.setGeometry(340, 30, 201, 20)
self.line_edit_gender.addItems(['男', '女'])
# 身份证
label_id = QLabel(self)
label_id.setGeometry(580, 30, 54, 16)
label_id.setFont(font)
label_id.setText("身份证:")
self.line_edit_id = QLineEdit(self)
self.line_edit_id.setGeometry(660, 30, 221, 20)
# 地址
label_addr = QLabel(self)
label_addr.setGeometry(40, 110, 54, 16)
label_addr.setFont(font)
label_addr.setText("地址:")
self.line_edit_addr = QLineEdit(self)
self.line_edit_addr.setGeometry(92, 110, 141, 20)
# 电话
label_phone = QLabel(self)
label_phone.setGeometry(270, 70, 54, 16)
label_phone.setFont(font)
label_phone.setText("电话:")
self.line_edit_phone = QLineEdit(self)
self.line_edit_phone.setGeometry(340, 70, 201, 20)</code>*Disclaimer: This article is compiled from the internet; copyright belongs to the original author. If any source information is incorrect or infringes rights, please contact us for removal or authorization.
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.