python开发仓库管理系统_tkinter的应用--mini级《仓库管理系统》
[Python] 純文本查看 復(fù)制代碼"""
程序入口 : 界面調(diào)用其他模塊
(1)option.config : 配置文件
·init: False(默認(rèn)), 未初始化數(shù)據(jù)庫; true,數(shù)據(jù)庫已經(jīng)建立。 程序自己完成。
·host: 主機(jī);
·user: 數(shù)據(jù)庫用戶
·password:數(shù)據(jù)庫密碼
·database: 用戶數(shù)據(jù)庫( warehouse )
(2)settings.py: 基礎(chǔ)設(shè)置。
(3)mysql_connnect.py: 實(shí)現(xiàn)對數(shù)據(jù)庫的各種操作
(4)gui.py: 程序UI設(shè)計(jì), 程序入口
"""
import tkinter as tk
import tkinter.messagebox
from tkinter import Menu
from tkinter import ttk
import time
import settings
import mysql_connect as sql
import re
# 登錄類
class sign_frame( tk.Frame ):
def __init__(self, **kwargs ):
super().__init__( **kwargs)
tk.Label( self, text="登錄", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
tk.Label( self, text="賬號: ", width= 14, height=2, font=("楷體", 12),bg="palegreen", anchor="w")\
.place(x =150, y=100 )
self.user_id = tk.Entry(self, width=20)
self.user_id.place(x= 300, y=110)
tk.Label( self, text="密碼: ", width= 14, height=2, font=("楷體", 12),bg="palegreen",anchor="w" )\
.place(x =150, y=150 )
self.user_pw = tk.Entry(self, width=20)
self.user_pw.place(x= 300, y=160)
tk.Label( self, text="重新輸入密碼: ", width= 14, height=2, font=("楷體", 12),bg="palegreen",anchor="w" )\
.place(x =150, y=200 )
self.user_pw2 = tk.Entry(self, width=20)
self.user_pw2.place(x= 300, y=210)
tk.Button( self, text="登錄", width=10,height=1, command=self.check).place(x=150, y=270 )
tk.Button( self, text="退出", width=10,height=1, command=self.quit_user).place(x=365, y=270 )
def check(self):
user_id = self.user_id.get()
user_pw = self.user_pw.get()
user_pw2 = self.user_pw2.get()
# Todo 測試結(jié)束后刪除
#user_id ="root"
#user_pw = user_pw2 = "root"
if(user_pw != user_pw2):
tk.messagebox.showwarning(title='提示', message='密碼不一致!')
else:
# done 登錄驗(yàn)證
ans = sql.check_sign(user_id, user_pw)
if ans[0] :
tk.messagebox.showinfo( title="提示",message="登陸成功!")
settings.user["name"] = ans[1]
settings.user["id"] = user_id
else:
tk.messagebox.showwarning(title='提示', message='密碼錯(cuò)誤!')
tk.Label( master=root ,text="昵稱:{}\t\t賬號:{}".format( settings.user["name"], settings.user["id"] ))\
.place(x=50, y=10)
def quit_user(self):
settings.user["name"] = ""
settings.user["id"] = ""
tk.Label( master=root ,text="昵稱:{}\t\t賬號:{}".format( settings.user["name"], settings.user["id"] ),
width=200, anchor="w")\
.place(x=50, y=10)
# 購貨管理
class purchase_frame( tk.Frame ):
def __init__(self, **kwargs):
super().__init__( **kwargs)
tk.Label( self, text="購貨管理", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
# 實(shí)現(xiàn)訂貨
tk.Label( self, text="訂貨", width=10,height=2, font=("黑體",13),bg="palegreen" ).place(x=100,y=70)
tk.Label( self, text="商品名:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=90)
self.name = tk.Entry(self, width=18 )
self.name.place(x=100,y=100 )
tk.Label( self, text="數(shù)量 :", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=120)
self.num = tk.Entry( self, width=18)
self.num.place(x=100, y=130)
tk.Label( self, text="單價(jià):", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=150)
self.price = tk.Entry( self, width=18)
self.price.place(x=100, y=160)
tk.Label( self, text="供貨商:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=180)
self.shop = tk.Entry( self, width=18)
self.shop.place(x=100, y=190)
tk.Label( self, text="聯(lián)系方式:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=210)
self.phone = tk.Entry( self, width=18)
self.phone.place(x=100, y=220)
tk.Button(self, text="確認(rèn)訂貨", width=10,height=1, command=self.order_goods).place(x=10, y=270 )
tk.Button(self, text="重置", width=10,height=1, command=self.set_entry).place(x=150, y=270 )
# 實(shí)現(xiàn)收貨和退貨
tk.Label( self, text="訂貨清單", width=10,height=2, font=("黑體",13),bg="palegreen" ).place(x=300,y=70)
self.info_list = tk.Listbox(self, width=40, height=13, font=("宋體",12))
self.info_list.place(x=250,y=100)
self.add_inof_list()
menu = Menu(root, tearoff=0)
menu.add_command(label="收貨", command=self.get_goods)
menu.add_command(label="查看信息", command= self.show_info_selected)
#menu.add_separator()
menu.add_command(label="退貨", command= self.return_goods)
self.menu = menu
# 鼠標(biāo)右鍵彈出菜單
self.info_list.bind("", self.popupmenu)
# 收貨
def get_goods(self):
loc = self.info_list.curselection()[0]
data = str( self.info_list.get(loc) ).split(" ")
title = ['訂單編號:','商品名:','供貨商:','聯(lián)系方式:']
format_data = ""
for index in range( len( title) ):
format_data += str( title[index])+ str( data[index])+"\n"
if tk.messagebox.askyesno( title="確認(rèn)收貨", message=format_data):
self.info_list.delete(loc)
# done 數(shù)據(jù)庫修改
sql.change_goods_state_receving(data[0], data[1])
# 退貨處理
def return_goods(self):
loc = self.info_list.curselection()[0]
data = str( self.info_list.get(loc) ).split(" ")
title = ['訂單編號:','商品名:','供貨商:','聯(lián)系方式:']
format_data = ""
for index in range( len( title) ):
format_data += str( title[index])+ str( data[index])+"\n"
if tk.messagebox.askyesno( title="確認(rèn)退貨", message=format_data):
self.info_list.delete(loc)
# done 數(shù)據(jù)庫修改
sql.change_goods_state_back(data[0])
# 訂貨清單打開菜單
def popupmenu(self,event):
if len ( self.info_list.curselection()) :
self.menu.post(event.x_root, event.y_root)
# 添加訂貨清單信息
def add_inof_list(self):
# done 獲取數(shù)據(jù)庫信息
data = sql.get_goods_info_order()
for item in data:
self.info_list.insert('end', item )
# 訂貨
def order_goods(self):
id = self.get_id()
name = self.name.get()
num = self.num.get()
price = "%5.2f" % float( self.price.get())
state = "訂貨"
shop = self.shop.get()
phone = self.phone.get()
user_id = settings.user["id"]
show_data = "{} {} {} {}".format(id,name,shop, phone)
self.info_list.insert('end', show_data)
# done 寫入數(shù)據(jù)庫
sql.order_goods(id=id, name=name, num=num, price=price,shop=shop,phone=phone, user_id=user_id)
# 計(jì)算訂單編號
def get_id(self):
id_time = time.strftime('%Y-%m-%d',time.localtime(time.time()))
# DOne 讀取數(shù)據(jù)庫今日訂單數(shù)量
id_num = int(sql.get_purchase_day_sum( id_time ))
return str(id_time)+( "_{:0>4d}".format(id_num) )
# 清空訂貨信息(訂貨)
def set_entry(self):
self.name.delete(0,'end')
self.num.delete(0,'end')
self.price.delete(0,'end')
self.shop.delete(0,'end')
self.phone.delete(0,'end')
# 顯示訂單詳情( 狀態(tài) = ‘訂貨’)
def show_info_selected(self):
data = self.info_list.get( self.info_list.curselection()[0])
id = data.split(" ")[0]
# done 查詢訂單的詳細(xì)信息
data = sql.get_goods_detailed_info( id )
format_data = ""
for item in data:
format_data += str(item)+"\n"
tk.messagebox.showinfo( title="提示",message=format_data)
# 零售管理
class running_frame( tk.Frame ):
def __init__(self, **kwargs):
super().__init__( **kwargs)
tk.Label( self, text="零售管理", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
# 添加商品
tk.Label( self, text="商品名-編號", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=20,y=70)
tk.Label( self, text="單價(jià)", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=250,y=70)
tk.Label( self, text="數(shù)量", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=350,y=70)
tk.Label( self, text="合計(jì)", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=450,y=70)
self.name_id = ttk.Combobox(self,width=28)
self.name_id.bind("<>",self.update_goods_info)
self.name_id.place(x=20, y=100)
self.set_value()
self.price = tk.Spinbox(self,width=7, from_=0,to=100000,increment=1,command=self.change_num)
self.price.place( x=250, y=100)
self.num = tk.Spinbox(self,width=7, from_=0,to=100000,increment=1)
self.num.place( x=350, y=100)
self.account = tk.Label(self, text="-----", width=10,height=1, font=("楷體",12),bg="palegreen",anchor="w" )
self.account.place(x=450,y=100)
tk.Button(self, text="單品合計(jì)", width=10,height=1, command=self.add_goods).place(x=510,y=90)
# 商品展示
self.goods_info = tk.Listbox(self, width=71, height=9, font=("宋體", 12))
self.goods_info.place(x=20,y=140)
# 商品清除
menu = Menu(root, tearoff=0)
menu.add_command(label="刪除", command=self.del_goods)
self.menu = menu
# 鼠標(biāo)右鍵彈出菜單
self.goods_info.bind("", self.popupmenu)
#總額計(jì)算
tk.Button( self,text="計(jì)算總和", width=10,height=1, command= self.all_account ).place(x=20, y=310)
tk.Button( self,text="清空商品", width=10,height=1, command= self.del_goods_info ).place(x=510, y=310)
self.money = tk.Label(self, text="-----", width=10,height=1, font=("楷體",12),bg="palegreen",anchor="w" )
self.money.place( x=200, y=310)
# 設(shè)置商品信息
def set_value(self):
# done 獲取庫存商品name id
data = sql.get_stock_goods_name_id()
self.name_id['value'] = data
#選擇商品后修改對應(yīng)數(shù)據(jù)
def update_goods_info(self,event):
name_id = str ( self.name_id.get() ).split(" ")
id = name_id[1]
# done 讀取商品的庫存價(jià)格
price = sql.get_stock_goods_price(id)
self.price.delete(0,'end')
self.price.insert(0, price)
# 修改價(jià)格整數(shù)為小數(shù)
def change_num(self):
data = self.price.get()
self.price.insert('end',".00")
# 計(jì)算商品價(jià)格 加入購物車
def add_goods(self):
name_id = self.name_id.get()
price = self.price.get()
num = self.num.get()
account = eval(price) * eval(num)
self.account['text'] = format(account, '>5.2f')
data = "{} {}/元 {}/個(gè) {}元".format(name_id, str(price), str(num), format(account, '>5.2f'))
self.goods_info.insert(0, data)
# 商品清單打開菜單
def popupmenu(self,event):
if len ( self.goods_info.curselection()) :
self.menu.post(event.x_root, event.y_root)
# 刪除商品--商品欄中清除
def del_goods(self):
loc = self.goods_info.curselection()[0]
data = str( self.goods_info.get(loc) ).replace(" ","\n")
if tk.messagebox.askyesno( title="確認(rèn)刪除", message=data):
self.goods_info.delete(loc)
# 計(jì)算商品總和
def all_account(self):
data = self.goods_info.get(0,'end')
money = float(0)
for item in data:
money += float ( str(item).split(" ")[-1][:-1] )
self.money['text'] = format( money, '<8.2f' )
# DOne 流水賬 輸入數(shù)據(jù)庫
sql.write_running( settings.user["id"] , data )
# 清空商品
def del_goods_info(self):
if tk.messagebox.askyesno( title="確認(rèn)刪除", message="清空商品欄?"):
self.goods_info.delete(0,'end')
self.money['text'] = "-----"
# 倉庫管理
class warehouse_frame( tk.Frame ):
def __init__(self, **kwargs):
super().__init__( **kwargs)
tk.Label( self, text="倉庫管理", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
# 查看存貨
tk.Label( self, text="商品名", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=20,y=70)
self.name = ttk.Combobox( self, width=20 )
self.name.place( x=20,y=100 )
self.set_name()
tk.Label( self, text="數(shù)量", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=250,y=70)
self.num_type = ttk.Combobox( self, width=1 )
self.num_type['value'] = ['>','=',"
self.num_type.current(0)
self.num_type.place( x=250,y=100 )
self.num_value = tk.Spinbox(self,width=4, from_=0,to=9999999,increment=1)
self.num_value.place( x=280,y=100 )
tk.Label( self, text="價(jià)格", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=350,y=70)
self.price_type = ttk.Combobox( self, width=1 )
self.price_type['value'] = ['>','=',"
self.price_type.current(0)
self.price_type.place( x=350,y=100 )
self.price_value = tk.Spinbox(self,width=4, from_=0,to=9999999,increment=1,command= self.set_price_value)
self.price_value.place( x=380,y=100 )
tk.Button(self, text="條件查詢", font=("楷體",12), command= self.find_stock).place(x=430,y=95)
tk.Button(self, text="查詢?nèi)?#34;, bg="gold",font=("楷體",12), command=self.find_all_stock).place(x=510,y=95)
# 庫存顯示
self.stock_info = tk.Listbox(self, width=80, height=10)
self.stock_info.place( x=20, y=150)
# 讀取庫存商品名
def set_name(self):
# done 讀取數(shù)據(jù)庫庫存商品名
data = sql.get_stock_goods_name_id()
self.name['value'] = data
# 按條件查詢庫存
def find_stock(self):
name = str ( self.name.get()).split(" ")[0]
num = self.num_type.get() + self.num_value.get()
price = self.price_type.get() + self.price_value.get()
# done 按條件查詢庫存
data = sql.get_stock_goods_price_and_num( name, num, price )
self.stock_info.delete(0,'end')
for item in data:
self.stock_info.insert('end', item )
# 查詢所有庫存
def find_all_stock(self):
# done 查詢?nèi)繋齑?/p>
data = sql.get_all_stock_info()
self.stock_info.delete(0,'end')
for item in data:
self.stock_info.insert('end', item )
# 格式化價(jià)格設(shè)置
def set_price_value(self):
self.price_value.insert('end','.00')
# 結(jié)算管理
class acount_frame( tk.Frame ):
def __init__(self, **kwargs):
super().__init__( **kwargs)
tk.Label( self, text="結(jié)算管理", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
# 查詢條件
tk.Label( self, text="查詢類型:", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=10,y=70)
self.type = ttk.Combobox(self, width=15 ,height=2)
self.type['value'] = ['購貨賬目','零售賬目']
self.type.place(x=90, y=75)
self.type.current(0)
tk.Label( self, text="開始時(shí)間:", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=10,y=100)
self.y1 = tk.Spinbox(self,width=6, from_=0,to=2050,increment=1, command= self.set_y1 )
self.y1.place(x=90,y=107)
self.y1.delete(0,'end')
self.y1.insert(0,'2020年')
self.m1 = tk.Spinbox(self,width=3, from_=1,to=12,increment=1, command= self.set_m1)
self.m1.place(x=145,y=107)
self.m1.delete(0,'end')
self.m1.insert(0,'1月')
self.d1 = tk.Spinbox(self,width=3, from_=1,to=31,increment=1, command= self.set_d1)
self.d1.place(x=180,y=107)
self.d1.delete(0,'end')
self.d1.insert(0,'1日')
tmp_time = time.strftime('%Y-%m-%d',time.localtime(time.time())).split("-")
tk.Label( self, text="結(jié)束時(shí)間:", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=10,y=130)
self.y2 = tk.Spinbox(self,width=6, from_=0,to=2050,increment=1, command= self.set_y2 )
self.y2.place(x=90,y=137)
self.y2.delete(0,'end')
self.y2.insert(0,'{}年'.format(tmp_time[0]))
self.m2 = tk.Spinbox(self,width=3, from_=1,to=12,increment=1, command= self.set_m2)
self.m2.place(x=145,y=137)
self.m2.delete(0,'end')
self.m2.insert(0,'{}月'.format(tmp_time[1]))
self.d2 = tk.Spinbox(self,width=3, from_=1,to=31,increment=1, command= self.set_d2)
self.d2.place(x=180,y=137)
self.d2.delete(0,'end')
self.d2.insert(0,'{}日'.format(tmp_time[2]))
tk.Label( self, text="操作員:", width=20,height=2, font=("楷體",12),bg="palegreen",anchor="w").place(x=10,y=160)
self.user = ttk.Combobox(self, width=15 ,height=2)
self.user.place(x=90, y=165)
self.set_user_val()
tk.Button(self, text="查詢", width=28,height=1, command=self.find_info).place(x=10, y=240 )
# 查詢結(jié)果顯示
self.ans_info = tk.Listbox(self, width=45,height=15, font=('宋體',12))
self.ans_info.place( x=220, y=70)
self.ans_info.bind("", self.show_detailed_ans_info)
# 顯示詳細(xì)信息
def show_detailed_ans_info(self,event):
type = self.ans_info.curselection()
if type and type[0]>0:
id = self.ans_info.get( type[0] )
# todo 獲取詳細(xì)信息
data = sql.get_detailed_info( str( self.ans_info.get(0)).strip(), str(id).split(" ")[0] )
tk.messagebox.showinfo(title= str( self.ans_info.get(0) ).strip(), message=data )
# 設(shè)置查詢條件--操作員
def set_user_val(self):
# DOne 獲取操作員id_name
data = sql.get_user_name_id()
self.user['value'] = data
# 查詢信息
def find_info(self):
type = self.type.get()
start_time = re.sub( r"[年月日]","","%s-%03s-%03s" % ( str(self.y1.get()),str( self.m1.get()),str(self.d1.get() )) )
end_time = re.sub( r"[年月日]","","%s-%03s-%03s" % ( str(self.y2.get()), str(self.m2.get()),str(self.d2.get()) ) )
start_time.replace(" ",'0')
end_time.replace(" ",'0')
try:
user_id = str( self.user.get() ).split("__")[1]
except Exception as e:
user_id = ""
# done 讀取數(shù)據(jù)庫
data = sql.find_running_or_purchase( type, start_time, end_time, user_id)
self.ans_info.delete(0,'end')
for item in data:
self.ans_info.insert('end', item )
# 設(shè)置偽日歷
def set_y1(self):
self.y1.insert('end','年')
def set_m1(self):
self.m1.insert('end','月')
def set_d1(self):
self.d1.insert('end','日')
def set_y2(self):
self.y2.insert('end','年')
def set_m2(self):
self.m2.insert('end','月')
def set_d2(self):
self.d2.insert('end','日')
# 管理員
class manger_frame( tk.Frame ):
def __init__(self, **kwargs):
super().__init__( **kwargs)
tk.Label( self, text="管理員", width=10,height=2, font=("黑體",15),bg="cyan" ).place(x=250,y=10)
self.place(x=160, y=40)
# 實(shí)現(xiàn) 添加賬號
tk.Label( self, text="添加賬號", width=10,height=2, font=("黑體",13),bg="palegreen" ).place(x=90,y=60)
tk.Label( self, text="昵稱:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=90)
self.name = tk.Entry(self, width=18 )
self.name.place(x=120,y=100 )
tk.Label( self, text="賬號 :", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=120)
self.id = tk.Entry( self, width=18)
self.id.place(x=120, y=130)
tk.Label( self, text="密碼:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=150)
self.pw = tk.Entry( self, width=18)
self.pw.place(x=120, y=160)
tk.Label( self, text="再次輸入密碼:", width=13,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=180)
self.pw2 = tk.Entry( self, width=18)
self.pw2.place(x=120, y=190)
tk.Label( self, text="等級:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=210)
self.grade = ttk.Combobox( self, width=16)
self.grade.place(x=120, y=220)
self.grade['value'] = ['管理員','普通操作員']
self.grade.current(1)
tk.Button(self, text="添加賬號", width=10,height=1, command=self.add_account).place(x=10, y=270 )
tk.Button(self, text="重置", width=10,height=1, command=self.reset_entry).place(x=170, y=270 )
# 實(shí)現(xiàn)刪除和修改信息
tk.Label( self, text="賬號", width=10,height=2, font=("黑體",13),bg="palegreen" ).place(x=300,y=60)
self.account_list = tk.Listbox(self, width=35, height=13, font=("宋體",12))
self.account_list.place(x=280,y=100)
self.add_account_list()
menu = Menu(root, tearoff=0)
menu.add_command(label="修改信息", command=self.change_pw)
menu.add_command(label="刪除賬號", command= self.del_account)
self.menu = menu
# 鼠標(biāo)右鍵彈出菜單
self.account_list.bind("", self.popupmenu)
# 商品清單打開菜單
def popupmenu(self,event):
if len ( self.account_list.curselection()) :
self.menu.post(event.x_root, event.y_root)
# 添加賬號
def add_account(self):
name = self.name.get()
id = self.id.get()
pw = self.pw.get()
pw2 = self.pw2.get()
grade = self.grade.get()
# done 添加賬號,寫入數(shù)據(jù)庫
if name=="" or id=="" or grade=="":
tk.messagebox.showwarning( title="添加賬號", message="請?zhí)钊胝_的數(shù)據(jù)!")
else:
if not pw==pw2:
tk.messagebox.showwarning( title="密碼", message="密碼不一致!")
else:
if sql.add_user(name, id, pw, grade):
tk.messagebox.showinfo(title="添加賬號" ,message="添加成功!")
info = "{} {} {} {}".format(name, id, pw,grade)
self.account_list.insert('end', info )
else:
tk.messagebox.showerror(title="添加賬號", message="賬號已存在,請修改賬號!")
# 修改信息界面
def change_pw(self):
# 獲取數(shù)據(jù)
data = str ( self.account_list.get( self.account_list.curselection()[0] ) )
data = data.split(" ")
print( data )
# 界面
child = tk.Toplevel()
child.geometry("280x210+100+100")
child.config( bg="palegreen")
child.title("修改賬號信息")
tk.Label( child, text="昵稱:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=20)
name = tk.Entry(child, width=18 )
name.place(x=120,y=30 )
name.insert(0, data[0] )
tk.Label( child, text="賬號 :", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=50)
id = tk.Label( child, width=18, text=str(data[1]), anchor="w" )
id.place(x=120, y=60)
tk.Label( child, text="密碼:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=80)
pw = tk.Entry( child, width=18)
pw.insert( 0,data[2][2:] )
pw.place(x=120, y=90)
tk.Label( child, text="等級:", width=10,height=2, font=("楷體",12),bg="palegreen",anchor="w" ).place(x=10,y=110)
grade = ttk.Combobox( child, width=16)
grade.place(x=120, y=120)
grade['value'] = ['管理員','普通操作員']
grade.current(1)
if data[3] == "管理員":
grade.current(0)
tk.Button(child, text="修改信息", width=10,height=1, command=lambda :self.change_account(str(data[1]), name, pw,grade)).place(x=10, y=170 )
tk.Button(child, text="退出", width=10,height=1, command=child.destroy ).place(x=170, y=170 )
child.mainloop()
# 修改信息
def change_account(self, id, name,pw, grade):
name = name.get()
pw = pw.get()
grade = grade.get()
if name=="" or pw=="" or grade=="":
tk.messagebox.showwarning(title="修改用戶信息", message="請正確填寫相關(guān)數(shù)據(jù)!")
else:
# done 修改用戶信息
sql.update_user_info(id, name, pw, grade)
self.account_list.delete(0,'end')
self.add_account_list()
# 刪除賬號
def del_account(self):
loc = self.account_list.curselection()[0]
data = str( self.account_list.get(loc) ).split(" ")
title = ['昵稱:','賬號:','密碼:','登記:']
format_data = ""
for index in range( len(data) ):
format_data += title[ index]+data[index]+"\n"
if tk.messagebox.askyesno( title="確認(rèn)刪除", message=data):
self.account_list.delete(loc)
# done 數(shù)據(jù)庫修改
sql.del_user( data[1] )
# 獲取已存在賬號信息
def add_account_list(self):
# done 獲取管理員信息
data = sql.get_user_info()
self.account_list.delete(0,'end')
for item in data:
self.account_list.insert('end', item)
# 重置輸入框
def reset_entry(self):
self.name.delete(0,'end')
self.id.delete(0,'end')
self.pw.delete(0,'end')
self.pw2.delete(0,'end')
self.grade.current(0)
# 管理員登錄 - settings.manger_signing( False/ True)
def manger_sign( frame, tmp_frame):
child = tk.Toplevel( )
child.geometry("300x230+100+100")
child.config( bg="palegreen")
child.title("管理員登錄")
# 管理員登錄信息
tk.Label(child, width=10, height=2, text="賬號: ", anchor="w",bg="palegreen", font=("黑體", 12) ).place(x=20, y=20)
user_id = tk.Entry( child, width=20 )
user_id.place(x=130, y=25 )
tk.Label(child, width=10, height=2, text="密碼: ", anchor="w",bg="palegreen", font=("黑體", 12) ).place(x=20, y=60)
user_pw = tk.Entry( child, width=20 )
user_pw.place(x=130, y=65 )
tk.Label(child, width=13, height=2, text="再次輸入密碼: ", anchor="w",bg="palegreen", font=("黑體", 12) ).place(x=20, y=100)
user_pw2 = tk.Entry( child, width=20 )
user_pw2.place(x=130, y=105 )
# 操作
tk.Button(child, width=10, height=1, text="登錄", command=lambda : manger_sign_check( frame, tmp_frame, child, user_id.get(), user_pw.get(), user_pw2.get())).place(x=20, y=165)
tk.Button(child, width=10, height=1, text="重置", command=lambda : reset_manger_sign_info( user_id, user_pw, user_pw2)).place(x=190, y=165)
child.mainloop()
# 管理員登錄
def manger_sign_check(frame, tmp_frame, child, user_id, user_pw, user_pw2 ):
if not user_pw==user_pw2:
print( user_pw, user_pw2)
tk.messagebox.showwarning( title="管理員登錄", message="密碼不一致!")
else:
# done 管理員登錄
data,name = sql.manger_sign( user_id, user_pw)
if data :
tk.messagebox.showinfo(title="提示", message="管理員:{}\n \t\t登錄成功!".format(name))
child.destroy()
settings.manger_signing = True
frame.destroy()
frame = exec(tmp_frame+"(master=root,width=600, height=350,bg='palegreen' )")
else:
tk.messagebox.showwarning(title="警告", message="管理員 登錄失敗!")
# 重置管理員登錄信息
def reset_manger_sign_info( user_id, user_pw, user_pw2 ):
user_id.delete(0,'end')
user_pw.delete(0,'end')
user_pw2.delete(0,'end')
# 實(shí)現(xiàn)頁面切換
def change_frame( frame, tmp_frame ):
if settings.user["name"] == '':
tk.messagebox.showerror(title="提示",message="請您登錄")
else:
if tmp_frame == "manger_frame":# 管理員登錄
manger_sign( frame, tmp_frame)
else:
if isinstance(frame, manger_frame):
settings.manger_signing = False
frame.destroy()
frame = exec(tmp_frame+"(master=root,width=600, height=350,bg='palegreen' )")
if __name__ == '__main__':
root = tk.Tk()
root.title("售貨管理系統(tǒng)")
root.geometry("800x400")
tk.Label( master=root ,text="昵稱:{}\t賬號:{}".format( settings.user["name"], settings.user["id"] ))\
.place(x=50, y=10)
frame = sign_frame( master=root,width=600, height=350,bg="palegreen")
purchase_button = tk.Button(master=root, text="登錄", width=10, height=2,
command= lambda : change_frame(frame, "sign_frame"))
purchase_button.place(x=50, y=40)
purchase_button = tk.Button(master=root, text="購貨管理", width=10, height=2,
command= lambda : change_frame(frame, "purchase_frame"))
purchase_button.place(x=50, y=100)
running_button = tk.Button(master=root, text="零售管理", width=10, height=2,
command= lambda : change_frame(frame, "running_frame") )
running_button.place(x=50, y=160)
warehouse_button = tk.Button(master=root, text="倉庫管理", width=10, height=2,
command= lambda : change_frame(frame, "warehouse_frame" ) )
warehouse_button.place(x=50, y=220)
acount_button = tk.Button(master=root, text="結(jié)算管理", width=10, height=2,
command= lambda : change_frame(frame, "acount_frame" ) )
acount_button.place(x=50, y=280)
manger_button = tk.Button(master=root, text="管理員", width=10, height=2,
command= lambda : change_frame( frame, "manger_frame" ) )
manger_button.place(x=50, y=340)
root.mainloop()
總結(jié)
以上是生活随笔為你收集整理的python开发仓库管理系统_tkinter的应用--mini级《仓库管理系统》的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win10多合一原版系统_如何制作Win
- 下一篇: 下载Windows10纯净官方镜像