程序设计思路:
该程序框架由我之前的客户管理系统与商品管理系统改制而来,核心是利用python中的tkinter制作GUI,用pymysql将python连接MySQL数据库进行数据支持,用Frame框架进行页面的滚动与切换,是具备一定功能性的二手交易平台程序
该程序具备会员的注册,客户的买卖,购物车与结账功能
会员的注册实现基于pymsql连接的MySQL数据库中的会员表的匹配
客户的买卖 卖是基本的增加商品功能 买则是将查询与购物车、结账三者结合形成的操作
主程序
import pymysql.cursors from tkinter import ttk import tkinter as tk import tkinter.font as tkFont from tkinter import * import tkinter.messagebox as messagebox import time import subprocess class logincheck: def __init__(self,parent_window): parent_window.update() parent_window.destroy() self.window=tk.Tk() self.window.title("会员登录界面") self.window.geometry('700x600+70+50') def open_other_python_program(): # 指定要启动的Python程序的路径 program_path = 'C:\\Users\\16226\\Desktop\\易物会员注册系统.py' # 使用subprocess模块启动程序 subprocess.Popen(['python', program_path]) Button(self.window, text="注册", font=tkFont.Font(size=16), command=open_other_python_program, width=10,height=2, fg='white', bg='pink').place(x=70, y=300) def getTime(): timeStr=time.strftime('%H:%M:%S') Rtime.configure(text=timeStr) self.window.after(1000, getTime) Rtime= Label(self.window,text='') Rtime.pack(pady=25) getTime() label = Label(self.window, text="易物二手交易登录", font=("楷体", 30)) label.config(fg="purple") label2 = Label(self.window, text="\n潘安俊、伍宇成、张宇飞、张雪", font=("楷体",15)) label.pack(pady=10) label2.pack(pady=10) self.var_username=StringVar() self.var_pwd=StringVar() self.right_top_username_label = Label(text="用户名:", font=('楷体', 15)).pack(pady=15) self.right_top_username_entry = Entry(textvariable=self.var_username, font=('楷体', 15)).pack() self.right_top_pwd_label = Label(text="密码:", font=('楷体', 15)).pack(pady=15) self.right_top_pwd_entry = Entry(textvariable=self.var_pwd, font=('楷体', 15)).pack() self.right_top_button1 = ttk.Button(text='确定', width=20, command=self.new_row).pack(pady=30) self.right_top_button2 = ttk.Button(text='返回', width=20, command=self.back).pack() self.window.protocol("WM_DELETE_WINDOW", self.back) self.username=[] self.pwd=[] self.window.mainloop() db = pymysql.connect(host="localhost", user="root", passwd="pananjun", db="cus") cursor = db.cursor() sql = "SELECT * FROM 会员表 WHERE 用户名='%s'"%(self.var_username.get()) try: cursor.execute(sql) results = cursor.fetchall() for row in results: self.username.append(row[0]) self.pwd.append(row[1]) except: print("Error: unable to fetch data") messagebox.showinfo('警告!', '数据库连接失败!') db.close() def back(self): self.window.destroy() def new_row(self): if self.var_username.get() != '' and self.var_pwd.get() != '' or self.var_username.get()=='test' and self.var_pwd.get()=='123': db = pymysql.connect(host="localhost", user="root", passwd="pananjun", db="cus") cursor= db.cursor() sql = "SELECT * FROM 会员表 WHERE 用户名='%s'"%(self.var_username.get()) try: cursor.execute(sql) startpage(self.window) except: db.rollback() messagebox.showinfo('警告!', '数据库连接失败!') db.close() else: messagebox.showinfo('提示!', '请填写正确的用户信息') class startpage: def __init__(self,parent_window): parent_window.update() parent_window.destroy() self.window=tk.Tk() self.window.title("易物二手奢侈品交易") self.window.geometry('1200x600+70+50') def switch_to_another_program(): subprocess.run(['python','查询.py'],shell=True) def open_other_python_program1(): # 指定要启动的Python程序的路径 program_path = 'C:\\Users\\16226\\Desktop\\购物车系统.py' # 使用subprocess模块启动程序 subprocess.Popen(['python', program_path]) def open_other_python_program2(): # 指定要启动的Python程序的路径 program_path = 'C:\\Users\\16226\\Desktop\\收货人系统.py' # 使用subprocess模块启动程序 subprocess.Popen(['python', program_path]) def getTime(): timeStr=time.strftime('%H:%M:%S') Rtime.configure(text=timeStr) self.window.after(1000, getTime) Rtime= Label(self.window,text='') Rtime.pack(pady=25) getTime() label= Label(self.window,text="易物二手奢侈品主页",font=("楷体",30)) label.pack(pady=10) Button(self.window,text="我要卖商品",font=tkFont.Font(size=16),command=lambda: xinjian(self.window),width=20,height=2,fg='white',bg='pink').place(x=100,y=300) Button(self.window,text="依据编号查询商品",font=tkFont.Font(size=16), command=lambda: cangkucha(self.window), width=20,height=2, fg='white', bg='gray').place(x=400, y=300) Button(self.window, text="删除购物车商品", font=tkFont.Font(size=16), command=lambda:shanchu(self.window), width=20,height = 2, fg = 'white', bg = 'gray').place(x=700, y=400) Button(self.window, text="我要买商品", font = tkFont.Font(size=16), command = lambda: kehudan(self.window), width = 20, height = 2, fg = 'white', bg = 'purple').place(x=100, y=400) Button(self.window, text="退出系统", font=tkFont.Font(size=16), command=self.window.destroy, width=20,height=2, fg='white', bg='gray').place(x=700, y=700) Button(self.window, text="修改商品信息", font=tkFont.Font(size=16), command=lambda:xiugai(self.window),width=20,height=2,fg='white',bg='gray').place(x=700,y=300) Button(self.window, text="依据商品名查询", font=tkFont.Font(size=16), command=lambda:cangkucha2(self.window), width=20,height=2, fg='white', bg='gray').place(x=400, y=400) Button(self.window, text="收货人管理", font=tkFont.Font(size=16), command=open_other_python_program2,width=20, height=2, fg='white', bg='gray').place(x=700, y=500) Button(self.window, text="购物车查看", font=tkFont.Font(size=16), command=lambda: kehudan0(self.window), width=20,height=2, fg='white', bg='green').place(x=100, y=500) Button(self.window, text="购物车结账", font=tkFont.Font(size=16), command=open_other_python_program1, width=20,height=2, fg='white', bg='green').place(x=400, y=500) self.window.mainloop() class xinjian: def __init__(self,parent_window): parent_window.destroy() self.window=tk.Tk() self.window.title("我要卖商品") self.window.geometry('700x600+70+50') self.top_title=Label(self.window,text="添加待售商品",bg='SkyBlue', font=('楷体', 20), width=70, height=2) self.top_title.pack() self.var_id = StringVar() self.var_name = StringVar() self.var_type = StringVar() self.var_p = StringVar() self.var_b = StringVar() self.var_new = StringVar() self.var_op = StringVar() self.var_num = StringVar() self.right_top_id_label = Label(text="商品编号:", font=('楷体', 15)).place(x=100,y=100) self.right_top_id_entry = Entry(textvariable=self.var_id, font=('楷体', 15)).place(x=200,y=100) self.right_top_name_label =Label(text="商品名称:", font=('楷体', 15)).place(x=300,y=100) self.right_top_name_entry = Entry(textvariable=self.var_name, font=('楷体', 15)).place(x=400,y=100) self.right_top_type_label = Label(text="商品品类:", font=('楷体', 15)).place(x=500,y=100) self.right_top_type_entry = Entry(textvariable=self.var_type, font=('楷体', 15)).place(x=600,y=100) self.right_top_p_label = Label(text="商品价格:", font=('楷体', 15)).place(x=100,y=200) self.right_top_p_entry = Entry(textvariable=self.var_p, font=('楷体', 15)).place(x=200,y=200) self.right_top_b_label = Label(text="商品品牌:",font=('楷体',15)).place(x=100,y=300) self.right_top_b_entry = Entry(textvariable=self.var_b, font=('楷体', 15)).place(x=200,y=300) self.right_top_num_label = Label(text="商品年份:", font=('楷体', 15)).place(x=100,y=400) self.right_top_num_entry = Entry(textvariable=self.var_num, font=('楷体', 15)).place(x=200,y=400) self.right_top_new_label = Label(text="商品成色:", font=('楷体', 15)).place(x=300,y=200) self.right_top_new_entry = Entry(textvariable=self.var_new, font=('楷体', 15)).place(x=400,y=200) self.right_top_op_label = Label(text="商品公价:", font=('楷体', 15)).place(x=300,y=400) self.right_top_op_entry = Entry(textvariable=self.var_op, font=('楷体', 15)).place(x=400,y=400) self.right_top_button1 = ttk.Button(text='确定', width=20, command=self