wxpython+sqlite超市管理系统的全部代码

时间: 2023-12-12 14:02:43 浏览: 37
由于超市管理系统的代码较为复杂,无法在此进行完整的展示,以下是一个简单的 wxpython+sqlite 超市管理系统的部分代码示例,供您参考: ```python import wx import sqlite3 class SuperMarket(wx.Frame): def __init__(self, parent, title): super(SuperMarket, self).__init__(parent, title=title, size=(800, 600)) self.InitUI() self.Centre() self.Show() def InitUI(self): # 创建菜单栏 menubar = wx.MenuBar() fileMenu = wx.Menu() fileMenu.Append(wx.ID_EXIT, '退出', '退出系统') menubar.Append(fileMenu, '&文件') self.SetMenuBar(menubar) self.Bind(wx.EVT_MENU, self.OnQuit, id=wx.ID_EXIT) # 创建左侧列表框 self.goods_list = wx.ListCtrl(self, style=wx.LC_REPORT) self.goods_list.InsertColumn(0, '商品编号', width=100) self.goods_list.InsertColumn(1, '商品名称', width=150) self.goods_list.InsertColumn(2, '商品价格', width=100) self.goods_list.InsertColumn(3, '商品库存', width=100) self.goods_list.InsertColumn(4, '商品分类', width=100) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnEdit, self.goods_list) # 创建右侧输入框 self.goods_id = wx.TextCtrl(self) self.goods_name = wx.TextCtrl(self) self.goods_price = wx.TextCtrl(self) self.goods_stock = wx.TextCtrl(self) self.goods_category = wx.ComboBox(self, choices=['食品', '饮料', '日用品', '化妆品']) # 创建按钮 self.btn_add = wx.Button(self, label='添加') self.btn_del = wx.Button(self, label='删除') self.btn_edit = wx.Button(self, label='编辑') # 创建布局 hbox1 = wx.BoxSizer(wx.HORIZONTAL) hbox1.Add(wx.StaticText(self, label='商品编号'), flag=wx.ALIGN_CENTER_VERTICAL) hbox1.Add(self.goods_id, proportion=1) hbox2 = wx.BoxSizer(wx.HORIZONTAL) hbox2.Add(wx.StaticText(self, label='商品名称'), flag=wx.ALIGN_CENTER_VERTICAL) hbox2.Add(self.goods_name, proportion=1) hbox3 = wx.BoxSizer(wx.HORIZONTAL) hbox3.Add(wx.StaticText(self, label='商品价格'), flag=wx.ALIGN_CENTER_VERTICAL) hbox3.Add(self.goods_price, proportion=1) hbox4 = wx.BoxSizer(wx.HORIZONTAL) hbox4.Add(wx.StaticText(self, label='商品库存'), flag=wx.ALIGN_CENTER_VERTICAL) hbox4.Add(self.goods_stock, proportion=1) hbox5 = wx.BoxSizer(wx.HORIZONTAL) hbox5.Add(wx.StaticText(self, label='商品分类'), flag=wx.ALIGN_CENTER_VERTICAL) hbox5.Add(self.goods_category, proportion=1) hbox6 = wx.BoxSizer(wx.HORIZONTAL) hbox6.Add(self.btn_add) hbox6.Add(self.btn_del) hbox6.Add(self.btn_edit) vbox1 = wx.BoxSizer(wx.VERTICAL) vbox1.Add(self.goods_list, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) vbox2 = wx.BoxSizer(wx.VERTICAL) vbox2.Add(hbox1, flag=wx.EXPAND|wx.TOP|wx.LEFT|wx.RIGHT, border=5) vbox2.Add(hbox2, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5) vbox2.Add(hbox3, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5) vbox2.Add(hbox4, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5) vbox2.Add(hbox5, flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=5) vbox2.Add(hbox6, flag=wx.ALIGN_CENTER|wx.BOTTOM|wx.TOP, border=5) hbox7 = wx.BoxSizer(wx.HORIZONTAL) hbox7.Add(vbox1, proportion=1, flag=wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=5) hbox7.Add(vbox2, proportion=0, flag=wx.EXPAND|wx.ALL, border=5) self.SetSizer(hbox7) # 连接数据库 self.conn = sqlite3.connect('supermarket.db') self.cur = self.conn.cursor() self.cur.execute('''CREATE TABLE IF NOT EXISTS Goods (id INT PRIMARY KEY NOT NULL, name TEXT NOT NULL, price REAL NOT NULL, stock INT NOT NULL, category TEXT NOT NULL)''') self.conn.commit() def OnQuit(self, e): self.Close() def OnEdit(self, e): index = e.GetIndex() item = self.goods_list.GetItem(index, 0) self.goods_id.SetValue(item.GetText()) item = self.goods_list.GetItem(index, 1) self.goods_name.SetValue(item.GetText()) item = self.goods_list.GetItem(index, 2) self.goods_price.SetValue(item.GetText()) item = self.goods_list.GetItem(index, 3) self.goods_stock.SetValue(item.GetText()) item = self.goods_list.GetItem(index, 4) self.goods_category.SetValue(item.GetText()) def LoadData(self): self.goods_list.DeleteAllItems() self.cur.execute('SELECT * FROM Goods') rows = self.cur.fetchall() for row in rows: index = self.goods_list.InsertItem(0, str(row[0])) self.goods_list.SetItem(index, 1, row[1]) self.goods_list.SetItem(index, 2, str(row[2])) self.goods_list.SetItem(index, 3, str(row[3])) self.goods_list.SetItem(index, 4, row[4]) def OnAdd(self, e): id = self.goods_id.GetValue() name = self.goods_name.GetValue() price = self.goods_price.GetValue() stock = self.goods_stock.GetValue() category = self.goods_category.GetValue() if id and name and price and stock and category: self.cur.execute('INSERT INTO Goods VALUES (?, ?, ?, ?, ?)', (id, name, price, stock, category)) self.conn.commit() self.LoadData() else: wx.MessageBox('请填写完整信息!', '错误', wx.OK|wx.ICON_ERROR) def OnDel(self, e): id = self.goods_id.GetValue() if id: self.cur.execute('DELETE FROM Goods WHERE id = ?', (id,)) self.conn.commit() self.LoadData() def OnEdit(self, e): id = self.goods_id.GetValue() name = self.goods_name.GetValue() price = self.goods_price.GetValue() stock = self.goods_stock.GetValue() category = self.goods_category.GetValue() if id and name and price and stock and category: self.cur.execute('UPDATE Goods SET name = ?, price = ?, stock = ?, category = ? WHERE id = ?', (name, price, stock, category, id)) self.conn.commit() self.LoadData() else: wx.MessageBox('请填写完整信息!', '错误', wx.OK|wx.ICON_ERROR) if __name__ == '__main__': app = wx.App() SuperMarket(None, title='超市管理系统') app.MainLoop() ``` 此代码仅为示例,实际情况可能存在差异,仅供参考。

相关推荐

最新推荐

recommend-type

wxpython+pymysql实现用户登陆功能

wxpython最为一款python GUI库,由于简单和轻便外加强大的功能而受到很多python爱好者的喜爱,pymysql作为python3.x版本连接mysql库,应用也非常广泛。今天利用这两个库写一个简单的用户登陆的GUI窗口界面: 1.先看...
recommend-type

wxpython实现按钮切换界面的方法

主要为大家详细介绍了wxpython实现按钮切换界面的方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

wxPython实现窗口用图片做背景

主要为大家详细介绍了wxPython实现窗口用图片做背景,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

python wxpython 实现界面跳转功能

wxpython没提供界面跳转的方式,所以就需要借助threading模块,本文给大家分享python wxpython 实现界面跳转功能,感兴趣的朋友跟随小编一起看看吧
recommend-type

WxPython实现无边框界面

主要为大家详细介绍了WxPython实现无边框界面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

机器学习怎么将excel转为csv文件

机器学习是一种利用计算机算法和统计数据的方法来训练计算机来进行自动学习的科学,无法直接将excel文件转为csv文件。但是可以使用Python编程语言来读取Excel文件内容并将其保存为CSV文件。您可以使用Pandas库来读取Excel文件,并使用to_csv()函数将其保存为CSV格式。以下是代码示例: ```python import pandas as pd # 读取 Excel 文件 excel_data = pd.read_excel('example.xlsx') # 将数据保存为 CSV 文件 excel_data.to_csv('example.csv', index=
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。