不少小伙伴问我,Python 怎么学,我的统一回答:实战,多练。其实就是从自己的兴趣出发,做一些实战小项目。
正好,周末在家摸鱼的时候,在网上看到了一个不错的小项目,用 Python 写一个疫苗管理系统的小项目。
很基础,适合新手学习,主要涉及 Python、Tkinter、数据库存储等知识。
获取前记得收藏、点赞支持一下。
方式①、微信搜索公众号:Python学习与数据挖掘,后台回复: 疫苗管理系统
方式②、添加微信号:dkl88194,备注:来自CSDN +疫苗管理系统
def connect_DBS(self, database, content):
db = pymysql.connect(host="localhost", user="root", psd="pwd", database=database)
cursor = db.cursor()
cursor.execute(content)
data = cursor.fetchone()
db.commit()
db.close()
return data
def main_window(self):
tk.Button(app, text='登录', bg='white', font=("Arial,12"), width=12, height=1, command=self.login).place(x=260, y=200)
tk.Button(app, text='注册', bg='white', font=("Arial,12"), width=12, height=1, command=self.register).place(x=260, y=240)
tk.Button(app, text='退出', bg='white', font=("Arial,12"), width=12, height=1, command=self.quit_mainloop).place(x=260, y=280)
def options(self):
options = tk.Toplevel(app)
options.title('功能选项')
options.geometry("600x500")
tk.Label(options, text="欢迎使用!", font=("KaiTi", 40)).place(x=180, y=15)
tk.Button(options, text='新建疫苗信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.add_vacc_info).place(x=100, y=100)
tk.Button(options, text='新建疫苗分配信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.add_vaccine_distr_info).place(x=100, y=160)
tk.Button(options, text='新建疫苗养护信息', bg='white', font=("Arial,12"), width=20, height=2, command=self.add_vaccine_maintenance_info).place(x=100, y=220)
tk.Button(options, text='新建接种人员信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.add_vaccination_person_info).place(x=100, y=280)
tk.Button(options, text='查询疫苗分配信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.vaccine_distr_info_query).place(x=100, y=340)
tk.Button(options, text='查询疫苗养护信息', bg='white', font=("Arial,12"), width=20, height=2, command=self.vaccination_maintenance_info_query).place(x=320, y=100)
tk.Button(options, text='查询接种人员信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.vaccination_person_info_query).place(x=320, y=160)
tk.Button(options, text='查询疫苗信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.vaccine_info_query).place(x=320, y=220)
tk.Button(options, text='修改疫苗信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.modify_vaccine_info).place(x=320, y=280)
tk.Button(options, text='删除疫苗信息', bg='white', font=("Arial,12"), width=20, height=2,command=self.del_vaccine_info).place(x=320, y=340)
def vaccine_distr_info_query(self):
query = tk.Toplevel(app)
query.title('信息查询')
query.geometry("600x400")
entry = tk.Entry(query, width=30)
entry.pack()
entry.place(x=200, y=80)
tk.Label(query, text="请输入疫苗分配单号:", font=("Arial", 9)).place(x=50, y=80)
tk.Label(query, text='查询结果:', font=('Arial', 9)).place(x=50, y=120)
text1 = tk.Text(query, width=50, height=20)
text1.pack()
text1.place(x=150, y=120)
def base_query():
vaccine_distr_num = entry.get()
print(vaccine_distr_num)
content = "SELECT * FROM vaccine_distr_info WHERE vaccine_distr_num = %s;" % vaccine_distr_num
data = self.connect_DBS(database="vaccine_info", content=content)
text1.delete(1.0, "end")
text1.insert(chars="{}".format(data), index="insert")
tk.Button(query, text='查询', bg='white', font=("Arial,12"), width=9, height=0, command=base_query).place(x=450,
y=75)
def vaccination_person_info_query(self):
query = tk.Toplevel(app)
query.title('接种人员信息查询')
query.geometry("600x400")
entry = tk.Entry(query, width=30)
entry.pack()
entry.place(x=200, y=80)
tk.Label(query, text="请输入接种人员身份证号:", font=("Arial", 9)).place(x=50, y=80)
tk.Label(query, text='查询结果:', font=('Arial', 9)).place(x=50, y=120)
text1 = tk.Text(query, width=50, height=20)
text1.pack()
text1.place(x=150, y=120)
def base_query():
ID_num = entry.get()
content = "SELECT * FROM vaccination_person_info WHERE ID_num = %s;" % ID_num
data = self.connect_DBS(database="vaccine_info", content=content)
text1.delete(1.0, "end")
text1.insert(chars="{}".format(data), index="insert")
tk.Button(query, text='查询', bg='white', font=("Arial,12"), width=9, height=0, command=base_query).place(x=450, y=75)
def vaccine_info_query(self):
query = tk.Toplevel(app)
query.title('疫苗信息查询')
query.geometry("600x400")
entry = tk.Entry(query, width=30)
entry.pack()
entry.place(x=200, y=80)
tk.Label(query, text="请输入疫苗批号:", font=("Arial", 9)).place(x=50, y=80)
tk.Label(query, text='查询结果:', font=('Arial', 9)).place(x=50, y=120)
text1 = tk.Text(query, width=50, height=20)
text1.pack()
text1.place(x=150, y=120)
def base_query():
vaccine_num = entry.get()
content = "SELECT * FROM vaccine_info WHERE vaccine_num = %s;" % vaccine_num
data = self.connect_DBS(database="vaccine_info", content=content)
text1.delete(1.0, "end")
text1.insert(chars="{}".format(data), index="insert")
tk.Button(query, text='查询', bg='white', font=("Arial,12"), width=9, height=0, command=base_query).place(x=450, y=75)
好了,就是这些内容,感兴趣的小伙伴,可以动手试一试。