Python实现简易商品管理系统

Python实现简易商品管理系统,第1张

import tkinter
import pymysql
conn=pymysql.connect(host="127.0.0.1",port=3306,user="root",password="123456",db="school",charset='utf8')
cursor=conn.cursor()
# 连接数据库,添加商品
cursor.execute("drop table if exists goods")
sql="create table goods(g_id int primary key auto_increment,g_name char(20),g_price int)"
cursor.execute(sql)
sql1="insert into goods(g_name,g_price) values('鞋子',200)"
cursor.execute(sql1)
conn.commit()
#编写按钮方法
def mClick1():
    name=txt1.get()
    print(name)
    sql2="select g_price from goods where g_name='%s'" %(name)
    cursor.execute(sql2)
    price=cursor.fetchall()
    txt2.set(price)
def mClick2():
    name=txt3.get()
    price=int(txt4.get())
    sql="update goods set g_price='%d' where g_name='%s'" %(price,name)
    cursor.execute(sql)
    conn.commit()
    txt1.set(name)

def mClick3():
    name=txt5.get()
    price=int(txt6.get())
    sql="insert into goods(g_name,g_price) values('%s','%d')" %(name,price)
    cursor.execute(sql)
    txt1.set(name)
    conn.commit()

win=tkinter.Tk()
win.title('简易商品管理系统')
win.geometry('500x100+200+200')
# 新增各个组建,使用grid布局
l1=tkinter.Label(win,text='查询的商品名称:')
l2=tkinter.Label(win,text='显示商品价格:')
l3=tkinter.Label(win,text='输入商品的名称:')
l4=tkinter.Label(win,text='输入调整价格:')
l5=tkinter.Label(win,text='输入新增商品名称:')
l6=tkinter.Label(win,text='输入商品价格:')

txt1=tkinter.StringVar()
e1=tkinter.Entry(win,textvariable=txt1,width=15)
txt2=tkinter.StringVar()
e2=tkinter.Entry(win,textvariable=txt2,width=15)
txt3=tkinter.StringVar()
e3=tkinter.Entry(win,textvariable=txt3,width=15)
txt4=tkinter.StringVar()
e4=tkinter.Entry(win,textvariable=txt4,width=15)
txt5=tkinter.StringVar()
e5=tkinter.Entry(win,textvariable=txt5,width=15)
txt6=tkinter.StringVar()
e6=tkinter.Entry(win,textvariable=txt6,width=15)

b1=tkinter.Button(win,text='查询',command=mClick1)
b2=tkinter.Button(win,text='修改',command=mClick2)
b3=tkinter.Button(win,text='添加',command=mClick3)


l1.grid(row=0,column=1)
e1.grid(row=0,column=2)
l2.grid(row=0,column=3)
e2.grid(row=0,column=4)
b1.grid(row=0,column=5)

l3.grid(row=1,column=1)
e3.grid(row=1,column=2)
l4.grid(row=1,column=3)
e4.grid(row=1,column=4)
b2.grid(row=1,column=5)

l5.grid(row=2,column=1)
e5.grid(row=2,column=2)
l6.grid(row=2,column=3)
e6.grid(row=2,column=4)
b3.grid(row=2,column=5)
win.mainloop()


 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/923099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存