1.描述
- Python实现增删改查(四)修改
2.思路
1)用户在页面双击,输入要修改的信息后,点击修改。
2)将程序打包成exe可执行文件
3)运行视频
3.代码
1)修改代码如下:
# 修改 def update_elshop(self): method = self.ui.tableWidget.currentRow() # 获取当前选中是第几行 # 如果未选中 if method < 0: QMessageBox.warning( self.ui, '提示', '您当前未选中任何商品') # 选中 else: shopId = self.ui.tableWidget.item(method, 0).text() # 获取第method行,第一列 shopName = self.ui.tableWidget.item(method, 1).text() # 获取第method行,第二列 shopPrice = self.ui.tableWidget.item(method, 2).text() # 获取第method行,第三列 cursor = self.connect.cursor() sql = "update elevenshop set shop_price = '{}' , shop_name = '{}' where shop_id = '{}'".format(shopPrice, shopName, shopId) cursor.execute(sql) self.connect.commit() QMessageBox.information( self.ui, '修改成功', '名称:{},价格:{},修改成功'.format(shopName, shopPrice)) self.select_elshop() # 刷新
2)打包exe文件指令
需要准备一张ico图标和py代码,在cmd中运行,以下2个代码都可以。
可以看到源文件(py源代码)和各种环境,体积较大。
pyinstaller elshop.py --noconsole --hidden-import PySide2.QtXml --icon="C:\Users\sywangu\Desktop\c\image\b.ico
看不到源代码,只会生成一个exe文件,体积较小。
pyinstaller --name="MyApplication" --windowed --onefile elshop.py --noconsole --hidden-import PySide2.QtXml --icon="C:\Users\sywangu\Desktop\c\image\b.ico