Python实现简易信息分类存储软件
作者:~白+黑 发布时间:2023-08-09 20:45:08
标签:Python,信息,分类存储,软件
时间紧任务重,女神提出的要求有模棱两可,只能自己考虑各种情况,除了用python还有谁能这么短的时间搞出来。
程序界面,增删改查不能少,后悔药也需要给女神准备上,由于最后需要打包给女神用,所以选择了python的自带库,tkinter编写界面,我觉得也不是那么丑,数据存储用sqlite3数据库,可以导出成csv文件,完全用python自带库解决,这样打包起来兼容性会好一点。
查询界面,可以根据每个表的各个项目分类查询,如果不输入查询关键字,则当前类别全部输出。
汇总信息展示,这里也是程序初始界面。
废话不多说,直接上代码,由于也是业余时间搞得,代码简单粗暴,缝缝补补,各位大神见笑了。
import tkinter as tk
import sqlite3
import csv
from threading import Thread
import shutil
import os
import time
from tkinter import messagebox
from tkinter import filedialog
from tkinter import ttk
class App(tk.Frame):
def __init__(self,master,*args,**kwargs):
super().__init__(master,*args,**kwargs)
self.dirdict={
"新建":self.new,
"查询":self.search,
"修改":self.edit,
"删除":self.delete,
"汇总":self.totale,
"导出":self.export,
"后悔药":self.regret
}
self.newdict={
"咨询信息":self.customer_information,
"投标信息":self.bidding_information,
"合同信息" :self.contract_information,
"售后信息" :self.service_information,
}
self.newlabelsdict={
"咨询信息":["日期","公司名称","联系人","联系电话","备注"],
"投标信息":["招标单位","招标号","报名费","保证金","退保证金","开票信息",],
"合同信息":["合同号","签订日期","数量","总价","客户名称","货期","派工单号","发货地址","回款批次","发票信息","开票信息","合同扫描件"],
"售后信息":["产品型号","派工号","货期","技术人员","安装人员","验收","售后1","售后2"],
}
self.prmkey={
"咨询信息":('company',1),
"投标信息":('company',0),
"合同信息":('contract',0),
"售后信息":('jobnum',1),
}
self.new_zh_col={
"咨询信息":'consulting',
"日期":"date","公司名称":"company","联系人":"contacts","联系电话":"telephone","备注":"remarks",
"投标信息":'bid',
"招标单位":"company","招标号":"number","报名费":"enroll","保证金":"ensure","退保证金":"back","开票信息":"invoice",
"合同信息":'contractinfo',
"合同号":"contract","签订日期":"sdate","数量":"quantity","总价":"total","客户名称":"customer","货期":"delivery","派工单号":"oddnum","发货地址":"address","回款批次":"batch","发票信息":"cinfo","开票信息":"invoice","合同扫描件":"catpath",
"售后信息":'service',
"产品型号":"product","派工号":"jobnum","货期":"delivery","技术人员":"artisan","安装人员":"installer","验收":"check","售后1":"service1","售后2":"service2",
}
self.pack(expand=1,fill="both")
self.con=sqlite3.connect("treasure.db")
self.creat_widget()
def creat_widget(self):
self.frameleft = tk.Frame(self,bg='RoyalBlue',relief="groove",borderwidth=2)
self.frameleft.pack(side='left',expand='no',fill='y',anchor="n")
for i in self.dirdict.keys():
but=tk.Button(self.frameleft,text=i,width="10",)
but.pack(side="top",expand="no",fill="x",anchor="n",padx=4,pady=5,)
but.bind('<Button-1>', self.set_style)
self.frameright = tk.Frame(self,bg='RoyalBlue',relief="groove",borderwidth=2)
self.frameright.pack(side='right',expand='yes',fill='both',padx=3,pady=0)
self.lf2 = tk.LabelFrame(self.frameright,text="信息",relief="groove",borderwidth=1,bg="Wheat")
self.lf2.pack(side="top",expand=1,fill="both",pady=2,)
self.totale()
def set_style(self,event):
for i in self.frameleft.winfo_children():
if isinstance(i,tk.Button):
i.config(fg="black")
event.widget["fg"]="blue"
self.reset(self.frameright)
self.lf1 = tk.Frame(self.frameright,relief="groove",borderwidth=0,bg='RoyalBlue')
self.lf1.pack(side="top",expand=0,fill="x",pady=2,)
self.lf2 = tk.LabelFrame(self.frameright,text="信息",relief="groove",borderwidth=1,bg="Wheat")
self.lf2.pack(side="top",expand=1,fill="both",pady=2,)
self.dirdict.get(event.widget["text"],None)()
self.lf2["text"]=event.widget["text"]
######################################新建内容###########################################################################
def new(self):#新建总类
def data_input(event):
self.lf2.config(text=event.widget['text'])
self.reset(self.lf2)
self.newdict.get(event.widget['text'],None)(self.newlabelsdict[event.widget['text']])
for i in self.newdict.keys():
bu=tk.Button(self.lf1,text=i,)
bu.pack(side="left",expand=1,fill="x",padx=5,pady=2,)
bu.bind('<Button-1>', data_input)
def customer_information(self,labellist):#新建客户信息
this="咨询信息"
for i in labellist:
if i == labellist[-1]:
tk.Label(self.lf2,text=i,bg="Wheat",width=10).pack(side="top",)
tk.Text(self.lf2,height=6).pack(side="top",expand=1,pady=1,padx=5,fill="both")
else:
e=tk.Entry(self.lf2,)
e.pack(side="top",expand=0,pady=1,padx=5,fill="x")
l=tk.Label(e,text=i,bg="Wheat",width=10)
l.pack(side="right",)
def getdict():
cusdict=self.super_get(labellist,self.lf2)
if self.save_data("INSERT INTO consulting VALUES (?,?,?,?,?)", list(cusdict.values())):
self.super_del(self.lf2)
bu=tk.Button(self.lf2,text="确认提交",width=15,command=getdict)
bu.pack(side="bottom",expand=0,padx=5,pady=2,)
def bidding_information(self,labellist):#新建招标信息
this="投标信息"
for i in labellist:
if i == labellist[-1]:
tk.Label(self.lf2,text=i,bg="Wheat",width=10).pack(side="top",)
tk.Text(self.lf2,height=6).pack(side="top",expand=1,pady=1,padx=5,fill="both")
else:
e=tk.Entry(self.lf2,)
e.pack(side="top",expand=0,pady=1,padx=5,fill="x")
l=tk.Label(e,text=i,bg="Wheat",width=10)
l.pack(side="right",)
def getdict():
cusdict=self.super_get(labellist,self.lf2)
if self.save_data("INSERT INTO bid VALUES (?,?,?,?,?,?)", list(cusdict.values())):
self.super_del(self.lf2)
bu=tk.Button(self.lf2,text="确认提交",width=15,command=getdict)
bu.pack(side="bottom",expand=0,padx=5,pady=2,)
def contract_information(self,labellist):#新建合同信息
this="合同信息"
def filenames():
names=filedialog.askopenfilenames(title="上传合同扫描件")
if names:
filenamesentry.insert(0,",".join(names))
for i in labellist:
if i==labellist[0]:
connum=tk.Entry(self.lf2,)
connum.pack(side="top",expand=0,pady=1,padx=5,fill="x")
tk.Label(connum,text=i,bg="Wheat",width=10).pack(side="right",)
elif i == labellist[-2]:
tk.Label(self.lf2,text=i,bg="Wheat",width=10).pack(side="top",)
tk.Text(self.lf2,height=6).pack(side="top",expand=1,pady=1,padx=5,fill="both")
elif i==labellist[-1]:
filenamesentry=tk.Entry(self.lf2)
filenamesentry.pack(side="top",expand=0,pady=2,padx=5,fill="x")
filebut=tk.Button(filenamesentry,text="点击上传合同",height=1,command=filenames)
filebut.pack(side="right",expand=0,padx=0,pady=0,)
else:
e=tk.Entry(self.lf2,)
e.pack(side="top",expand=0,pady=1,padx=5,fill="x")
tk.Label(e,text=i,bg="Wheat",width=10).pack(side="right",)
def getdict():
files=filenamesentry.get()
if files:
number=connum.get() if connum.get() else "无合同号"
newcat=os.path.join(os.getcwd(),"mydata\{}{}".format(number,time.strftime(r"-%Y-%m-%d %H-%M-%S",time.localtime()),))
os.mkdir(newcat)
for i in files.split(","):
shutil.move(os.path.join(i),newcat)
filenamesentry.delete(0, "end")
filenamesentry.insert(0,newcat)
cusdict=self.super_get(labellist,self.lf2)
if self.save_data("INSERT INTO contractinfo VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", list(cusdict.values())):
self.super_del(self.lf2)
bu=tk.Button(self.lf2,text="确认提交",width=15,command=getdict)
bu.pack(side="bottom",expand=0,padx=5,pady=2,fill="x")
def service_information(self,labellist):#新建售后信息
this="售后信息"
for i in labellist:
e=tk.Entry(self.lf2,)
e.pack(side="top",expand=0,pady=1,padx=5,fill="x")
l=tk.Label(e,text=i,bg="Wheat",width=10)
l.pack(side="right",)
def getdict():
cusdict=self.super_get(labellist,self.lf2)
# check=self.check(self.new_zh_col.get(this,None),self.prmkey.get(this,None)[0],cusdict.get())
if self.save_data("INSERT INTO service VALUES (?,?,?,?,?,?,?,?)", list(cusdict.values())):
self.super_del(self.lf2)
bu=ttk.Button(self.lf2,text="确认提交",width=15,command=getdict)
bu.pack(side="bottom",expand=0,padx=5,pady=2,)
#################################################################################################################
def save_data(self,sqldoc,somedata,flag=False):#数据库存储存储客户信息
cur = self.con.cursor()
try:
cur.execute(sqldoc,somedata)
self.con.commit()
messagebox.showinfo("禀报女王","女王万岁,您又赢了")
return True
except Exception as e:
messagebox.showwarning("急报女王","女王我出错了:{}".format(e))
return False
def check(self,this,col,value):
sqldoc="SELECT * FROM {} WHERE {} = '{}' ".format(this,col,value)
cur = self.con.cursor()
cur.execute(sqldoc)
data=cur.fetchone()
return data
def find_data(self,sqldoc):
cur = self.con.cursor()
try:
cur.execute(sqldoc)
datas=cur.fetchall()
if datas:
return datas
else:
messagebox.showwarning("禀报女王","女王大人,小的什么也没搜到")
except Exception as e:
messagebox.showwarning("禀报女王","女王大人这是一次失误{}".format(e))
return None
def del_data(self,sqldoc):
cur = self.con.cursor()
cur.execute(sqldoc)
self.con.commit()
messagebox.showinfo("喜报","女王无敌,敌人已消灭")
def add_top(self,title):#创建顶级窗口
top = tk.Toplevel(width=self.master.winfo_screenwidth()//4,height=self.master.winfo_screenheight()//4,)
top.title(title)
return top
def reset(self,widget):#重置该组件,销毁该组件所有子组件
for i in widget.winfo_children():
i.destroy()
def super_get(self,labellist,wids):#获取entry和text类得内容
cusdict={}
for i ,k in zip(labellist,[i for i in wids.winfo_children() if isinstance(i, (tk.Entry,tk.Text))]):
if isinstance(k,tk.Entry):
cusdict[i] = k.get()
elif isinstance(k, tk.Text):
cusdict[i] = k.get(1.0,'end')
else:
pass
return cusdict
def super_del(self,wids):#删除entry和text类的内容
for wid in wids.winfo_children():
if isinstance(wid,tk.Text):
wid.delete(1.0,"end")
elif isinstance(wid, tk.Entry):
wid.delete(0,"end")
else:
pass
def super_insert(self,wids,text):#为entry或text类组件插入内容
ins=[i for i in wids.winfo_children() if isinstance(i, (tk.Entry,tk.Text))]
for wid,value in zip(ins,text):
wid.insert("end",value)
def creat_tree(self,wid,headers,height=4):#建立treeview组件
tree=ttk.Treeview(wid,columns=headers,show='headings',height=height)
for n,i in enumerate(headers):
tree.column(i,width=60,)
tree.heading(column=i,text=i)
sc=ttk.Scrollbar(wid,)
sc['command']=tree.yview
sc.pack(side='right',fill='both')
tree["yscrollcommand"]=sc.set
tree.pack(side="top",fill="both",expand=1)
return tree
def tree_insert(self,table,datas):#插入数值
# 插入数据
if datas:
for index, data in enumerate(datas):
table.insert('', index, values=data)
def tree_del(self,obj):#清除组件内内容
child=obj.get_children()
for i in child:
obj.delete(i)
def create_lf1_children(self,parent,):#为一下项目提供筛选,搜索选项
def change(event):
cominfo["values"]=self.newlabelsdict[com.get()]
cominfo.current(0)
com=ttk.Combobox(parent,values=tuple(self.newlabelsdict.keys()),state="readonly",)
com.pack(side="left",padx=2,pady=2)
com.current(0)
com.bind('<<ComboboxSelected>>', change)
cominfo=ttk.Combobox(parent,state="readonly",values=self.newlabelsdict[com.get()])
cominfo.pack(side="left",padx=2,pady=2)
cominfo.current(0)
e=ttk.Entry(parent,)
e.pack(side="left",expand=1,pady=1,padx=5,fill="x")
return com,cominfo,e
def start_find(self,arc,colname,e):#便捷函数,为以下项目提供支持
tablename, col = self.new_zh_col.get(arc,None),self.new_zh_col.get(colname,None)
self.lf2.config(text=arc)
headers=self.newlabelsdict.get(arc,None)
table=self.creat_tree(self.lf2,headers)
par=e.get()
sqldoc="SELECT * FROM {} WHERE {} LIKE '%{}%' ".format(tablename,col,par) if par else "SELECT * FROM {} ".format(tablename)
datas=self.find_data(sqldoc)
return table ,datas
def search(self):#查找数据
def find():
self.reset(self.lf2)
arc=com.get()
colname = cominfo.get()
table,datas=self.start_find(arc,colname,e)
self.tree_insert(table,datas)
com, cominfo, e= self.create_lf1_children(self.lf1, )
tk.Button(self.lf1,text="开始查找",command=find).pack(side="left",expand=0,padx=5,pady=2,)
def edit(self):#编辑数据
def tree_selected(event):
name=com.get()
value_e=event.widget.item(event.widget.selection()[0])['values']
self.reset(self.lf2)
self.newdict.get(name,None)(self.newlabelsdict[name])
self.super_insert(self.lf2,value_e)
def find():
self.reset(self.lf2)
arc=com.get()
colname = cominfo.get()
table,datas=self.start_find(arc,colname,e)
self.tree_insert(table,datas)
table.bind("<<TreeviewSelect>>", tree_selected)
com, cominfo, e = self.create_lf1_children(self.lf1, )
tk.Button(self.lf1,text="开始查找",command=find).pack(side="left",expand=0,padx=5,pady=2,)
def delete(self):
def tree_selected(event):
name=com.get()
value_e=event.widget.item(event.widget.selection()[0])['values']
flag=messagebox.askokcancel('爱之深恨之切',"女王大人,确定要放弃它嘛")
if flag:
sqldoc="DELETE FROM {} WHERE {} = '{}' ".format(self.new_zh_col.get(name,None),self.prmkey.get(name,None)[0],value_e[self.prmkey.get(name,None)[1]])
self.del_data(sqldoc)
find()
else:
pass
def find():
self.reset(self.lf2)
arc=com.get()
colname = cominfo.get()
table,datas=self.start_find(arc, cominfo, e)
self.tree_insert(table,datas)
table.bind("<<TreeviewSelect>>", tree_selected)
com, cominfo, e = self.create_lf1_children(self.lf1, )
tk.Button(self.lf1,text="开始查找",command=find).pack(side="left",expand=0,padx=5,pady=2,)
def export(self):#导出数据,存为csv文件
def ex():
cur = self.con.cursor()
file=os.path.join(os.getcwd(),"{}{}.csv".format("数据汇总",time.strftime(r"-%Y-%m-%d %H-%M",time.localtime()),))
print(file)
with open(file,"w",newline="") as dd:
wter=csv.writer(dd)
for i in self.newlabelsdict.keys():
sqldoc="SELECT * FROM {} ".format(self.new_zh_col.get(i,None))
cur.execute(sqldoc)
datas=cur.fetchall()
wter.writerow(self.newlabelsdict[i])
wter.writerows(datas)
wter.writerow("")
messagebox.showinfo("喜报","女王陛下,数据已导出完成\n存储位置{}".format(file))
def beifen():
t = Thread(target=ex)
t.run()
cur = self.con.cursor()
for i, k in self.newlabelsdict.items():
lf21=tk.LabelFrame(self.lf2,text=i,bg="Wheat")
lf21.pack(side="top",fill="both",expand=1,pady=1)
sqldoc="SELECT * FROM {} ".format(self.new_zh_col.get(i,None))
cur.execute(sqldoc)
datas=cur.fetchall()
tk.Label(lf21,text="{}数据总数: {}条".format(i,len(datas)),font=("bold",15),bg="Wheat").pack(side="top",expand=1,fill="x")
tk.Button(self.lf2,text="导出数据",command=beifen,width=15).pack(side="bottom",expand=0,padx=5,pady=2,)
def totale(self):
cur = self.con.cursor()
for i, k in self.newlabelsdict.items():
lf21=tk.LabelFrame(self.lf2,text=i)
lf21.pack(side="top",fill="both",expand=1,pady=1)
table=self.creat_tree(lf21,k)
sqldoc="SELECT * FROM {} ".format(self.new_zh_col.get(i,None))
cur.execute(sqldoc)
datas=cur.fetchall()
self.tree_insert(table,datas)
def regret(self):
def eat():
self.con.rollback()
messagebox.showinfo("回到从前","女王大人,我们再次回到了从前")
tk.Label(self.lf2,text="女王陛下,该吃药了!!",font=("bold",30,),bg="Wheat").pack(side="top",expand=1,fill="x")
tk.Button(self.lf2,text="立即嗑药",command=eat,width=15).pack(side="bottom",expand=0,padx=5,pady=2,)
if __name__ == "__main__":
if not os.path.exists("mydata"):
os.mkdir("mydata")
root = tk.Tk()
# root.option_add("*Font", "微软雅黑")
root.iconbitmap('crown.ico')
root.title("女王的宝库")
# root.attributes("-alpha", 0.9)透明度设置,奈何女神不需要
root.geometry("{}x{}+{}+{}".format(root.winfo_screenwidth()//2,root.winfo_screenheight()//2,root.winfo_screenwidth()//4,root.winfo_screenheight()//4))
app=App(root)
app.mainloop()
来源:https://blog.csdn.net/weixin_43287121/article/details/121950813
0
投稿
猜你喜欢
- 项目地址:https://github.com/cgDeepLearn/BilibiliCrawler 项目特点采取了一定的反反爬
- 原数据lambda函数处理我之前写了各种if substr函数,各种报错正确到热泪盈眶的函数data['Followers/Fans
- 一、记事本源码#python简易记事本from tkinter import *from tkinter import messagebox
- 八种获取当前日期的js代码,第一步:把如下代码加入<head>区域中:<SCRIPT language=java
- 有时候,我们可能想在django中写一些代码来测试某些功能,我们希望在django项目中单独运行某个python文件来做这项测试工作。但是如
- python批量命名照片的具体代码,供大家参考,具体内容如下废话不多说,上效果图全部代码from tkinter import *impor
- 1、首先在系统盘中查找scrrun.dll,如果存在这个文件,请跳到第三步,如果没有,请执行第二步。 2、在安装文件目录i386中找到scr
- 之前画图一直在用matlibplot、pyecharts,最近学习了一个新的可视化库–cufflinks,用了两天我已经深深爱上它了主要是因
- 排序排序是指以特定格式排列数据。排序算法指定以特定顺序排列数据的方式。最常见的顺序是数字或字典顺序。在 Numpy 中,我们可以使用库中提供
- optimizer.param_groups: 是长度为2的list,其中的元素是2个字典;optimizer.param_groups[0
- 继续练手,根据之前获取汽油价格的方式获取了金价,暂时没钱投资,看看而已#!/usr/bin/env python# -*- coding:
- 结合mysql数据库查询,实现分页效果@user.route("/user_list",methods=['PO
- 两个容器,一个flask-demo,一个是redis-server在一个自定义网络bridge,相互ping,不需要知道ip,只用名字就能p
- zipfile是python里用来做zip格式编码的压缩和解压缩的,由于是很常见的zip格式,所以这个模块使用频率也是比较高的zipfile
- 创意404页面的文章我们似乎已经出过两篇了,今天hongkiat又带来了60个创意404页面.相关404页面设计文章:国外404错误页面的创
- 注意:首先你电脑必须安装git版本控制器(软件),在官网下载即可。pycharm中使用git以及github很简单,首先在设置中搜索gith
- 目录 一个简单的实现使用BSF(宽度优先搜索)进行实现使用DFA(Deterministic Finite Automaton)进
- 本文用163邮箱进行了测试,python用的是3.8版本进行的测试1.设置邮箱,如下图所示2.设置过程如下图所示:设置完成后,添加如下代码:
- bs4解析原理:1.实例化一个BeautifulSoup对象,并且将页面源码数据加载到该对象中2.通过调用BeautifulSoup对象中相
- '-----------------------------------------------------------