python+tkinter实现学生管理系统


Posted in Python onAugust 20, 2019

本文实例为大家分享了python+tkinter实现学生管理系统的具体代码,供大家参考,具体内容如下 

python+tkinter实现学生管理系统

from tkinter import *
from tkinter.messagebox import *
import sqlite3
from tkinter import ttk
 
dbstr = "H:\mydb.db"
 
root = Tk()
root.geometry('700x1000')
root.title('学生管理系统')
 
Label(root, text="学号:").place(relx=0, rely=0.05, relwidth=0.1)
Label(root, text="姓名:").place(relx=0.5, rely=0.05, relwidth=0.1)
Label(root, text="电话:").place(relx=0, rely=0.1, relwidth=0.1)
Label(root, text="地址:").place(relx=0.5, rely=0.1, relwidth=0.1)
 
sid = StringVar()
name = StringVar()
phone = StringVar()
address = StringVar()
Entry(root, textvariable=sid).place(relx=0.1, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=name).place(relx=0.6, rely=0.05, relwidth=0.37, height=25)
 
Entry(root, textvariable=phone).place(relx=0.1, rely=0.1, relwidth=0.37, height=25)
Entry(root, textvariable=address).place(relx=0.6, rely=0.1, relwidth=0.37, height=25)
 
Label(root, text='学生信息管理', bg='white', fg='red', font=('宋体', 15)).pack(side=TOP, fill='x')
 
 
def showAllInfo():
 x = dataTreeview.get_children()
 for item in x:
  dataTreeview.delete(item)
 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 lst = cur.fetchall()
 for item in lst:
  dataTreeview.insert("", 1, text="line1", values=item)
 cur.close()
 con.close()
 
 
def appendInfo():
 if sid.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif name.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif phone.get() == "":
  showerror(title='提示', message='输入不能为空')
 elif address.get() == "":
  showerror(title='提示', message='输入不能为空')
 else:
  x = dataTreeview.get_children()
  for item in x:
   dataTreeview.delete(item)
  list1 = []
  list1.append(sid.get())
  list1.append(name.get())
  list1.append(phone.get())
  list1.append(address.get())
  con = sqlite3.connect(dbstr)
  cur = con.cursor()
  cur.execute("insert into student values(?,?,?,?)", tuple(list1))
  con.commit()
  cur.execute("select * from student")
  lst = cur.fetchall()
  for item in lst:
   dataTreeview.insert("", 1, text="line1", values=item)
  cur.close()
  con.close()
 
 
def deleteInfo():
 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 studentList = cur.fetchall()
 cur.close()
 con.close()
 print(studentList)
 
 num = sid.get()
 flag = 0
 if num.isnumeric() == False:
  showerror(title='提示', message='删除失败')
 for i in range(len(studentList)):
  for item in studentList[i]:
   if int(num) == item:
    flag = 1
    con = sqlite3.connect(dbstr)
    cur = con.cursor()
    cur.execute("delete from student where id = ?", (int(num),))
    con.commit()
    cur.close()
    con.close()
    break
 if flag == 1:
  showinfo(title='提示', message='删除成功!')
 else:
  showerror(title='提示', message='删除失败')
 
 x = dataTreeview.get_children()
 for item in x:
  dataTreeview.delete(item)
 
 con = sqlite3.connect(dbstr)
 cur = con.cursor()
 cur.execute("select * from student")
 lst = cur.fetchall()
 for item in lst:
  dataTreeview.insert("", 1, text="line1", values=item)
 cur.close()
 con.close()
 
 
Button(root, text="显示所有信息", command=showAllInfo).place(relx=0.2, rely=0.2, width=100)
Button(root, text="追加信息", command=appendInfo).place(relx=0.4, rely=0.2, width=100)
Button(root, text="删除信息", command=deleteInfo).place(relx=0.6, rely=0.2, width=100)
 
 
dataTreeview = ttk.Treeview(root, show='headings', column=('sid', 'name', 'phone', 'address'))
dataTreeview.column('sid', width=150, anchor="center")
dataTreeview.column('name', width=150, anchor="center")
dataTreeview.column('phone', width=150, anchor="center")
dataTreeview.column('address', width=150, anchor="center")
 
dataTreeview.heading('sid', text='学号')
dataTreeview.heading('name', text='名字')
dataTreeview.heading('phone', text='电话')
dataTreeview.heading('address', text='地址')
 
dataTreeview.place(rely=0.3, relwidth=0.97)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中MYSQLdb出现乱码的解决方法
Oct 11 Python
Python中绑定与未绑定的类方法用法分析
Apr 29 Python
Python标准库之collections包的使用教程
Apr 27 Python
Python cookbook(数据结构与算法)将多个映射合并为单个映射的方法
Apr 19 Python
Django项目实战之用户头像上传与访问的示例
Apr 21 Python
python中计算一个列表中连续相同的元素个数方法
Jun 29 Python
Python3 读、写Excel文件的操作方法
Oct 20 Python
Django框架orM与自定义SQL语句混合事务控制操作
Jun 27 Python
详解Python time库的使用
Oct 10 Python
Python函数递归调用实现原理实例解析
Aug 11 Python
利用python为PostgreSQL的表自动添加分区
Jan 18 Python
Pytorch GPU内存占用很高,但是利用率很低如何解决
Jun 01 Python
Python对列表的操作知识点详解
Aug 20 #Python
python中的global关键字的使用方法
Aug 20 #Python
python并发编程 Process对象的其他属性方法join方法详解
Aug 20 #Python
浅谈pytorch grad_fn以及权重梯度不更新的问题
Aug 20 #Python
解决Pytorch 训练与测试时爆显存(out of memory)的问题
Aug 20 #Python
python中用logging实现日志滚动和过期日志删除功能
Aug 20 #Python
python3中替换python2中cmp函数的实现
Aug 20 #Python
You might like
PHP中::、->、self、$this几种操作符的区别介绍
2013/04/24 PHP
php+ajax实现带进度条的上传图片功能【附demo源码下载】
2016/09/14 PHP
浅谈PHP中pack、unpack的详细用法
2018/03/12 PHP
javascript 操作select下拉列表框的一点小经验
2010/03/20 Javascript
js innerHTML 改变div内容的方法
2013/08/03 Javascript
jQuery判断checkbox(复选框)是否被选中以及全选、反选实现代码
2014/02/21 Javascript
跨域请求的完美解决方法(JSONP, CORS)
2016/06/12 Javascript
第九篇Bootstrap导航菜单创建步骤详解
2016/06/21 Javascript
Javascript中常用的检测方法小结
2016/10/08 Javascript
js实现将json数组显示前台table中
2017/01/10 Javascript
基于jquery实现二级联动效果
2017/03/30 jQuery
Angular中响应式表单的三种更新值方法详析
2017/08/22 Javascript
基于ajax和jsonp的原生封装(实例)
2017/10/16 Javascript
详解React项目的服务端渲染改造(koa2+webpack3.11)
2018/03/19 Javascript
bootstrap自定义样式之bootstrap实现侧边导航栏功能
2018/09/10 Javascript
详解Vue路由自动注入实践
2019/04/17 Javascript
angular4+百分比进度显示插件用法示例
2019/05/05 Javascript
解决微信小程序云开发中获取数据库的内容为空的方法
2019/05/15 Javascript
java实现单链表增删改查的实例代码详解
2019/08/30 Javascript
Node.js API详解之 net模块实例分析
2020/05/18 Javascript
js闭包的9个使用场景
2020/12/29 Javascript
跟老齐学Python之Python文档
2014/10/10 Python
Python简单实现TCP包发送十六进制数据的方法
2016/04/16 Python
Python OpenCV利用笔记本摄像头实现人脸检测
2020/08/20 Python
Numpy 多维数据数组的实现
2020/06/18 Python
python GUI模拟实现计算器
2020/06/22 Python
html5 兼容IE6结构的实现代码
2012/05/14 HTML / CSS
canvas里面如何基于随机点绘制一个多边形的方法
2018/06/13 HTML / CSS
中文系师范生自荐信
2013/10/01 职场文书
酒店led欢迎词
2014/01/09 职场文书
高中生的自我评价
2014/03/04 职场文书
小学音乐教师个人工作总结
2015/02/05 职场文书
民政工作个人总结
2015/02/28 职场文书
2019年让高校“心动”的自荐信
2019/03/25 职场文书
Vue接口封装的完整步骤记录
2021/05/14 Vue.js
Python pyecharts案例超市4年数据可视化分析
2022/08/14 Python