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模拟登录百度代码分享(获取百度贴吧等级)
Dec 27 Python
深入讲解Java编程中类的生命周期
Feb 05 Python
Python 多线程抓取图片效率对比
Feb 27 Python
Python基于time模块求程序运行时间的方法
Sep 18 Python
python 除法保留两位小数点的方法
Jul 16 Python
Python 保存矩阵为Excel的实现方法
Jan 28 Python
详解将Pandas中的DataFrame类型转换成Numpy中array类型的三种方法
Jul 06 Python
Python Lambda函数使用总结详解
Dec 11 Python
使用Python制作缩放自如的圣诞老人(圣诞树)
Dec 25 Python
Python3 利用face_recognition实现人脸识别的方法
Mar 13 Python
PyQt5+Pycharm安装和配置图文教程详解
Mar 24 Python
Python标准库pathlib操作目录和文件
Nov 20 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
AM/FM收音机的安装与调试
2021/03/02 无线电
解析Extjs与php数据交互(增删查改)
2013/06/25 PHP
PHP中使用FFMPEG获取视频缩略图和视频总时长实例
2014/05/04 PHP
ThinkPHP入口文件设置及相关注意事项分析
2014/12/05 PHP
PHP利用APC模块实现文件上传进度条的方法
2015/01/26 PHP
PHP PDOStatement::errorCode讲解
2019/01/31 PHP
PHP封装请求类实例分析【基于Yii框架】
2019/10/17 PHP
Extjs学习笔记之一 初识Extjs之MessageBox
2010/01/07 Javascript
JavaScript 判断日期格式是否正确的实现代码
2011/07/04 Javascript
JavaScript使用pop方法移除数组最后一个元素用法实例
2015/04/06 Javascript
浅谈JavaScript中的this指针和引用知识
2016/08/05 Javascript
angular实现表单验证及提交功能
2017/02/01 Javascript
JavaScript实现跟随滚动缓冲运动广告框
2017/07/15 Javascript
JavaScript实现多重继承的方法分析
2018/01/09 Javascript
video.js 一个页面同时播放多个视频的实例代码
2018/11/27 Javascript
Vue.js组件实现选项卡以及切换特效
2019/07/24 Javascript
layui实现数据表格自定义数据项
2019/10/26 Javascript
vue 指令和过滤器的基本使用(品牌管理案例)
2019/11/04 Javascript
如何在JavaScript中创建具有多个空格的字符串?
2020/02/23 Javascript
2020京东618叠蛋糕js脚本(亲测好用)
2020/06/02 Javascript
pygame学习笔记(1):矩形、圆型画图实例
2015/04/15 Python
详解Python循环作用域与闭包
2019/03/21 Python
使用Python实现企业微信的自动打卡功能
2019/04/30 Python
pytorch使用指定GPU训练的实例
2019/08/19 Python
python 并发编程 多路复用IO模型详解
2019/08/20 Python
Django REST framwork的权限验证实例
2020/04/02 Python
纯CSS3制作的简洁蓝白风格的登录模板(非IE效果更好)
2013/08/11 HTML / CSS
小程序瀑布流解决左右两边高度差距过大的问题
2019/02/20 HTML / CSS
遮罩层 + Iframe实现界面自动显示的示例代码
2020/04/26 HTML / CSS
Notino匈牙利:购买香水和化妆品
2019/04/12 全球购物
美国运动鞋类和服装零售连锁店:Shoe Palace
2019/08/13 全球购物
珍惜时间演讲稿
2014/05/14 职场文书
垃圾分类的活动方案
2014/08/15 职场文书
通知格式
2015/04/27 职场文书
公司晚宴祝酒词
2015/08/11 职场文书
Linux中Nginx的防盗链和优化的实现代码
2021/06/20 Servers