Python-Based Shopping Mall System with Customer and Merchant Interfaces
This article describes a Python‑implemented shopping mall project that provides separate merchant and customer desktop applications built with PyQt5, details the system’s features, file structure, server‑client communication, database setup, execution steps, and includes the complete source code for reference.
The project is a Python application that implements both a customer side and a merchant side for an online shopping mall.
Features include merchant registration, login, shop information management, product addition, deletion, modification, search, and transaction record viewing; and customer registration, login, product search, purchase, order cancellation, and transaction history.
Merchant side consists of shopMain.py (UI logic), the shop folder for interface code, ui2 for Qt Designer UI files, and send_data.py for JSON communication with the server.
Customer side consists of customerMain.py , the customer folder for UI code, ui1 for Qt Designer UI files, and the same send_data.py for server interaction.
Server side includes server.py , which processes requests from merchants and customers and uses mysql_op.py to operate the MySQL database.
Project execution steps: create the database and tables using mall.sql , run server.py to start the server, then run shopMain.py for merchants or customerMain.py for customers.
Interface screenshots illustrate merchant registration, login, main interface, product management, transaction viewing, and shop information, as well as corresponding customer screens for registration, login, main interface, product browsing, purchasing, and order management.
Main code (Python with PyQt5):
import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import shop.register_window
from shop.register_window import *
from shop.login_window import *
from shop.shop_main import *
from shop.add_goods import *
from shop.view_goods import *
from shop.change_goods import *
from shop.update_goods import *
from shop.view_trade import *
from shop.shop_info import *
from send_data import *
class Register(QMainWindow, Ui_register_window):
def __init__(self, parent=None):
super(Register, self).__init__(parent)
self.setupUi(self)
self.reg_bt.clicked.connect(self.click1)
self.tologin.clicked.connect(self.click2)
def click1(self):
username = self.username.text()
pass1 = self.pass1.text()
pass2 = self.pass2.text()
shop_name = self.shop_name.text()
phone = self.phone.text()
addr = self.addr.currentText()
if username == '' or pass1 == '' or shop_name == '' or phone == '' or addr == '':
QMessageBox.information(self, "注册", "店铺信息不能为空", QMessageBox.Yes)
return
if pass1 != pass2:
QMessageBox.information(self, "注册", "两次密码不同", QMessageBox.Yes)
return
data = {'id': 'shop', 'type': 'register', 'user': username,
'passwd': pass1, 'shop_name': shop_name, 'phone': phone, 'addr': addr}
s = Send_data()
recv = s.message(data)
s.close()
if recv['result'] == 'success':
QMessageBox.information(self, "注册", "注册成功", QMessageBox.Yes)
else:
QMessageBox.information(self, "注册", "注册失败", QMessageBox.Yes)
def click2(self):
myWin1.hide()
myWin2.show()
class Login(QMainWindow, Ui_login_window):
def __init__(self, parent=None):
super(Login, self).__init__(parent)
self.setupUi(self)
self.login_bt.clicked.connect(self.click1)
self.toreg.clicked.connect(self.click2)
def click1(self):
global user
username = self.username.text()
password = self.password.text()
if username == '' or password == '':
QMessageBox.information(self, "登录", "用户名和密码不能为空", QMessageBox.Yes)
return
data = {'id': 'shop', 'type': 'login',
'user': username, 'passwd': password}
s = Send_data()
recv = s.message(data)
s.close()
if recv['result'] == 'success':
QMessageBox.information(self, "登录", "登录成功", QMessageBox.Yes)
user = username
myWin2.hide()
myWin3.show()
else:
QMessageBox.information(self, "登录", "登录失败", QMessageBox.Yes)
def click2(self):
myWin2.hide()
myWin1.show()
# ... (remaining class definitions for Mainwin, Addgoods, Viewgoods, Changegoods, Updategoods, Viewtrade, Shopinfo) ...
if __name__ == '__main__':
app = QApplication(sys.argv)
user = ""
myWin1 = Register()
myWin1.show()
myWin2 = Login()
myWin3 = Mainwin()
myWin4 = Addgoods()
myWin5 = Viewgoods()
myWin6 = Changegoods()
myWin7 = Viewtrade()
myWin8 = Shopinfo()
myWin9 = Updategoods()
if app.exec_() == 0:
sys.exit(0)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.