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 相关文章推荐
ptyhon实现sitemap生成示例
Mar 30 Python
Python使用htpasswd实现基本认证授权的例子
Jun 10 Python
在Python的Flask框架中实现单元测试的教程
Apr 20 Python
Python 包含汉字的文件读写之每行末尾加上特定字符
Dec 12 Python
Python列表list内建函数用法实例分析【insert、remove、index、pop等】
Jul 24 Python
OpenCV HSV颜色识别及HSV基本颜色分量范围
Mar 22 Python
python五子棋游戏的设计与实现
Jun 18 Python
Django REST Framework之频率限制的使用
Sep 29 Python
Python Web静态服务器非堵塞模式实现方法示例
Nov 21 Python
Python3之外部文件调用Django程序操作model等文件实现方式
Apr 07 Python
Python importlib动态导入模块实现代码
Apr 16 Python
python中sqllite插入numpy数组到数据库的实现方法
Jun 21 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
Sorting Array Values in PHP(数组排序)
2011/09/15 PHP
使用php判断网页是否gzip压缩
2013/06/25 PHP
WordPress中登陆后关闭登陆页面及设置用户不可见栏目
2015/12/31 PHP
PHP错误和异常处理功能模块示例
2016/11/12 PHP
php微信开发之关键词回复功能
2018/06/13 PHP
php判断某个方法是否存在函数function_exists (),method_exists()与is_callable()区别与用法解析
2020/04/20 PHP
懒就要懒到底——鼠标自动点击(含时间判断)
2007/02/20 Javascript
dreamweaver 安装Jquery智能提示
2011/04/02 Javascript
JavaScript中连接操作Oracle数据库实例
2015/04/02 Javascript
javascript针对cookie的基本操作实例详解
2015/11/30 Javascript
js date 格式化
2017/02/15 Javascript
JS正则获取HTML元素的方法
2017/03/31 Javascript
原生javascript上传图片带进度条【实例分享】
2017/04/06 Javascript
vuejs绑定class和style样式
2017/04/11 Javascript
Vue.js 动态为img的src赋值方法
2018/03/14 Javascript
Angularjs中date过滤器失效的问题及解决方法
2018/07/06 Javascript
微信小程序实现保存图片到相册功能
2018/11/30 Javascript
vue实现的下拉框功能示例
2019/01/29 Javascript
vue2.0+SVG实现音乐播放圆形进度条组件
2019/09/21 Javascript
基于javascript实现贪吃蛇小游戏
2019/11/25 Javascript
Vue双向绑定实现原理与方法详解
2020/05/07 Javascript
python实现分析apache和nginx日志文件并输出访客ip列表的方法
2015/04/04 Python
在Python中操作时间之strptime()方法的使用
2020/12/30 Python
Python基于递归算法实现的走迷宫问题
2017/08/04 Python
python实现控制台打印的方法
2019/01/12 Python
Django-Model数据库操作(增删改查、连表结构)详解
2019/07/17 Python
python爬虫刷访问量 2019 7月
2019/08/01 Python
Python如何用filter函数筛选数据
2020/03/05 Python
在PyTorch中使用标签平滑正则化的问题
2020/04/03 Python
使用Pycharm分段执行代码
2020/04/15 Python
Html5应用程序缓存(Cache manifest)
2018/06/04 HTML / CSS
anello泰国官方网站:日本流行包包品牌
2019/08/08 全球购物
公司总经理任命书
2014/06/05 职场文书
个人查摆问题自查报告
2014/10/16 职场文书
浅谈pytorch中的dropout的概率p
2021/05/27 Python
TV动画《政宗君的复仇》第二季制作决定PV公布
2022/04/02 日漫