python-study-day1-(病人管理系统-带sql)

2024-04-11 18:04

本文主要是介绍python-study-day1-(病人管理系统-带sql),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

MainWindow代码

from tkinter import *
from tkinter import messagebox
from tkinter.ttk import Comboboxclass MianWindow(Frame):def __init__(self, master=None):super().__init__(master, padx=30, pady=20)self.flag = 0self.pack(expand=True, fill=BOTH)self.id = StringVar(value=' ')self.name = StringVar(value=' ')self.style = StringVar(value='')self.number = StringVar(value=' ')self.text_box = StringVar(value=' ')self.Xu_setup()def Xu_setup(self):container = Frame(self)container.pack(side=TOP, fill=X, expand=YES, pady=10)Button(master=container, text='增    加', width=10, command=self.Yao_add).pack(side=LEFT, padx=20, expand=YES)Button(master=container, text='更    改', width=10, command=self.Yao_update).pack(side=LEFT, padx=20, expand=YES)Button(master=container, text='删    除', width=10, command=self.Yao_del).pack(side=LEFT, padx=20, expand=YES)Button(master=container, text='查    询', width=10, command=self.Yao_select).pack(side=LEFT, padx=20, expand=YES)container = Frame(self)container.pack(side=TOP, fill=X, expand=YES, pady=20)lbl1 = Label(master=container, text="编     号", width=10, font=("微软雅黑", 11))lbl1.pack(side=LEFT, padx=5)self.ent1 = Entry(master=container, textvariable=self.id)self.ent1.pack(ipady=8, side=LEFT, padx=5)lbl2 = Label(master=container, text="姓      名", width=10, font=("微软雅黑", 11))lbl2.pack(side=LEFT, padx=5)self.ent2 = Entry(master=container, textvariable=self.name)self.ent2.pack(ipady=8, side=LEFT, padx=5, fill=X)lbl_box = Label(master=container, text="性       别", width=10, font=("微软雅黑", 11))lbl_box.pack(side=LEFT, padx=5)self.comboxlist = Combobox(master=container, textvariable=self.text_box, width=5)self.comboxlist["values"] = ("男", "女")self.comboxlist.current(0)self.comboxlist.bind("<<ComboboxSelected>>", self.func)self.comboxlist.pack(ipady=8, side=RIGHT, fill=X)container = Frame(self)container.pack(side=TOP, fill=X, expand=YES, pady=20)lbl3 = Label(master=container, text="病      型", width=10, font=("微软雅黑", 11))lbl3.pack(side=LEFT, padx=5)self.ent3 = Entry(master=container, textvariable=self.style)self.ent3.pack(ipady=8, side=LEFT, padx=5, fill=X, expand=YES)lbl4 = Label(master=container, text="年      龄", width=10, font=("微软雅黑", 11))lbl4.pack(side=LEFT, padx=5)self.ent4 = Entry(master=container, textvariable=self.number)self.ent4.pack(ipady=8, side=LEFT, padx=5, fill=X, expand=YES)container = Frame(self)container.pack(side=TOP, fill=X, expand=YES, pady=20)self.text = Text(master=container)scroll = Scrollbar()scroll.pack(side=RIGHT, fill=Y)scroll.config(command=self.text.yview)self.text.config(yscrollcommand=scroll.set)self.text.pack(fill=X, expand=YES)self.text.insert(INSERT, "")def func(self, *args):self.flag = 1print(self.flag)return self.flagdef clear(self):self.ent1.delete(0, "end")self.ent2.delete(0, "end")self.ent3.delete(0, "end")self.ent4.delete(0, "end")def Yao_add(self):if len(self.id.get()) == 0:messagebox.askokcancel("确定/退出对话框", "插入失败,编号为空")self.clear()returnif len(self.name.get()) == 0:messagebox.askokcancel("确定/退出对话框", "插入失败,名称为空")self.clear()returnif len(self.style.get()) == 0:messagebox.askokcancel("确定/退出对话框", "插入失败,病型为空")self.clear()returnif len(self.number.get()) == 0:messagebox.askokcancel("确定/退出对话框", "插入失败,年龄为空")self.clear()returnif self.flag == 0:messagebox.askokcancel("确定/退出对话框", "插入失败,性别未选")self.clear()returnelse:from Patient.db import Connectcon = Connect()con.Zhou_insert(int(self.id.get()),self.name.get(),self.text_box.get(),self.style.get(),self.number.get())messagebox.showinfo("打印信息对话框", "插入成功")self.clear()from Patient.db import Connectcon= Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)def Yao_update(self):if len(self.id.get()) != 0 and len(self.name.get()) != 0 and len(self.number.get()) != 0:from Patient.db import Connectcon = Connect()re = con.Zhou_update(int(self.id.get()), self.name.get(), self.number.get())if re:messagebox.askokcancel("确定/退出对话框", "执行成功")self.clear()from Patient.db import Connectcon = Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)else:messagebox.askokcancel("确定/退出对话框", "执行失败,或数据不存在")self.clear()returnreturnelif len(self.id.get()) != 0 and len(self.name.get()):from Patient.db import Connectcon = Connect()re = con.update_name(int(self.id.get()), self.name.get())if re:messagebox.askokcancel("确定/退出对话框", "执行成功")self.clear()from Patient.db import Connectcon = Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)else:messagebox.askokcancel("确定/退出对话框", "执行失败,或数据不存在在")self.clear()returnreturnelif len(self.id.get()) != 0 and len(self.number.get()) != 0:from Patient.db import Connectcon = Connect()re = con.update_number(int(self.id.get()), self.number.get())if re:messagebox.askokcancel("确定/退出对话框", "执行成功")self.clear()from Patient.db import Connectcon = Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)else:messagebox.askokcancel("确定/退出对话框", "执行失败,或数据不存在在")self.clear()returnreturnelse:messagebox.askokcancel("确定/退出对话框", "执行失败,或数据不存在在")self.clear()returndef Yao_del(self):from Patient.db import Connectcon = Connect()re = con.delete_id(int(self.id.get()))if re:messagebox.askokcancel("确定/退出对话框", "执行成功")self.clear()from Patient.db import Connectcon = Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)else:messagebox.askokcancel("确定/退出对话框", "执行失败,或数据不存在在")self.clear()returndef Yao_select(self):self.clear()from Patient.db import Connectcon = Connect()all_ = con.Print_result()for data in all_:s = "编号:%d \t姓名:%s\t性别:%s\t病型:%s\t年龄:%s\n\n" % dataself.text.insert(INSERT, s)if __name__ == '__main__':root = Tk()root.geometry('800x500')root.title("病人信息登记")MianWindow(root)root.mainloop()

db代码

import pymysql.cursorsclass Connect:def get_connect(self):self.connect = pymysql.Connect(host='localhost',port=3306,user='root',password='admin123',database='person',charset='utf8')self.cursor = self.connect.cursor()def Print_result(self):self.get_connect()sql = "select * from person"self.cursor.execute(sql)all_ = self.cursor.fetchall()for data in all_:print("编号:%d \t名称:%s \t性别:%s\t类型:%s\t数值:%s\n" % data)self.connect.commit()self.connect.close()return all_def Zhou_insert(self, id, name, sex, style, number):self.get_connect()sql = "insert into person (id,name ,sex,style,number) values (%d,'%s','%s','%s','%s')"self.cursor.execute(sql % (id, name, sex, style, number))self.connect.commit()self.connect.close()def Zhou_update(self, number, name, id):self.get_connect()sql = "UPDATE person SET number ='%s',name ='%s' WHERE id = %d;"re = self.cursor.execute(sql % (id, name, number))self.connect.commit()self.connect.close()return redef update_name(self, name, id):  #self.get_connect()try:sql = "UPDATE person SET name ='%s' WHERE id = %d;"re = self.cursor.execute(sql % (id, name))except pymysql.err:self.connect.commit()print("执行错误")finally:self.connect.close()return redef update_number(self, id, number):self.get_connect()sql = "UPDATE person SET number ='%s'WHERE id = %d;"re = self.cursor.execute(sql % (number, id))self.connect.commit()self.connect.close()return redef delete_id(self, id):self.get_connect()sql = "DELETE FROM person WHERE id = %d"re = self.cursor.execute(sql % id)self.connect.commit()self.connect.close()return reif __name__ == '__main__':c = Connect()

效果图

 部署

需要的私,v:13053025350

这篇关于python-study-day1-(病人管理系统-带sql)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/894792

相关文章

使用Python和OpenCV库实现实时颜色识别系统

《使用Python和OpenCV库实现实时颜色识别系统》:本文主要介绍使用Python和OpenCV库实现的实时颜色识别系统,这个系统能够通过摄像头捕捉视频流,并在视频中指定区域内识别主要颜色(红... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间详解

一文深入详解Python的secrets模块

《一文深入详解Python的secrets模块》在构建涉及用户身份认证、权限管理、加密通信等系统时,开发者最不能忽视的一个问题就是“安全性”,Python在3.6版本中引入了专门面向安全用途的secr... 目录引言一、背景与动机:为什么需要 secrets 模块?二、secrets 模块的核心功能1. 基

一文详解MySQL如何设置自动备份任务

《一文详解MySQL如何设置自动备份任务》设置自动备份任务可以确保你的数据库定期备份,防止数据丢失,下面我们就来详细介绍一下如何使用Bash脚本和Cron任务在Linux系统上设置MySQL数据库的自... 目录1. 编写备份脚本1.1 创建并编辑备份脚本1.2 给予脚本执行权限2. 设置 Cron 任务2

python常见环境管理工具超全解析

《python常见环境管理工具超全解析》在Python开发中,管理多个项目及其依赖项通常是一个挑战,下面:本文主要介绍python常见环境管理工具的相关资料,文中通过代码介绍的非常详细,需要的朋友... 目录1. conda2. pip3. uvuv 工具自动创建和管理环境的特点4. setup.py5.

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Python常用命令提示符使用方法详解

《Python常用命令提示符使用方法详解》在学习python的过程中,我们需要用到命令提示符(CMD)进行环境的配置,:本文主要介绍Python常用命令提示符使用方法的相关资料,文中通过代码介绍的... 目录一、python环境基础命令【Windows】1、检查Python是否安装2、 查看Python的安

SQL Server数据库死锁处理超详细攻略

《SQLServer数据库死锁处理超详细攻略》SQLServer作为主流数据库管理系统,在高并发场景下可能面临死锁问题,影响系统性能和稳定性,这篇文章主要给大家介绍了关于SQLServer数据库死... 目录一、引言二、查询 Sqlserver 中造成死锁的 SPID三、用内置函数查询执行信息1. sp_w

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Python中help()和dir()函数的使用

《Python中help()和dir()函数的使用》我们经常需要查看某个对象(如模块、类、函数等)的属性和方法,Python提供了两个内置函数help()和dir(),它们可以帮助我们快速了解代... 目录1. 引言2. help() 函数2.1 作用2.2 使用方法2.3 示例(1) 查看内置函数的帮助(