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 相关文章推荐
flask中使用SQLAlchemy进行辅助开发的代码
Feb 10 Python
理解Python中的With语句
Feb 02 Python
Python多线程编程(一):threading模块综述
Apr 05 Python
python统计文本文件内单词数量的方法
May 30 Python
Python实现处理管道的方法
Jun 04 Python
Python深入06——python的内存管理详解
Dec 07 Python
Python把对应格式的csv文件转换成字典类型存储脚本的方法
Feb 12 Python
在Python中使用Neo4j的方法
Mar 14 Python
使用 Django Highcharts 实现数据可视化过程解析
Jul 31 Python
Python的垃圾回收机制详解
Aug 28 Python
TensorFlow梯度求解tf.gradients实例
Feb 04 Python
Python 存取npy格式数据实例
Jul 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
destoon调用自定义模板及样式的公告栏
2014/06/21 PHP
PHP文件读写操作相关函数总结
2014/11/18 PHP
PHP实现的增强性mhash函数
2015/05/27 PHP
php实现表单多按钮提交action的处理方法
2015/10/24 PHP
php使用gearman进行任务分发操作实例详解
2020/02/26 PHP
jquery不会自动回收xmlHttpRequest对象 导致了内存溢出
2012/06/18 Javascript
jquery如何判断某元素是否具备指定的样式
2013/11/05 Javascript
javascript中数组中求最大值示例代码
2013/12/18 Javascript
JavaScript格式化日期时间的方法和自定义格式化函数示例
2014/04/04 Javascript
js监控IE火狐浏览器关闭、刷新、回退、前进事件
2014/07/23 Javascript
jQuery中parents()和parent()的区别分析
2014/10/28 Javascript
Javascript前端UI框架Kit使用指南之kitjs事件管理
2014/11/28 Javascript
angularjs的一些优化小技巧
2014/12/06 Javascript
判断访客终端类型集锦
2015/06/05 Javascript
动态加载js文件简单示例
2016/04/21 Javascript
Python 正则表达式(转义问题)
2014/12/15 Python
Python实现LRU算法的2种方法
2015/06/24 Python
利用Python开发微信支付的注意事项
2016/08/19 Python
Python socket套接字实现C/S模式远程命令执行功能案例
2018/07/06 Python
Python 给某个文件名添加时间戳的方法
2018/10/16 Python
Python Datetime模块和Calendar模块用法实例分析
2019/04/15 Python
python在OpenCV里实现投影变换效果
2019/08/30 Python
python实现简单飞行棋
2020/02/06 Python
python3.x中安装web.py步骤方法
2020/06/23 Python
新西兰最大的在线设计师眼镜店:SmartBuyGlasses新西兰
2017/10/20 全球购物
周仰杰(JIMMY CHOO)英国官方网站:闻名世界的鞋子品牌
2018/10/28 全球购物
苏格兰在线威士忌商店:The Whisky Barrel
2019/05/07 全球购物
在weblogic中发布ejb需涉及到哪些配置文件
2012/01/17 面试题
结婚周年感言
2014/02/24 职场文书
毕业寄语大全
2014/04/09 职场文书
党员学习正风肃纪思想汇报
2014/09/12 职场文书
大学生见习报告范文
2014/11/03 职场文书
SQL Server代理:理解SQL代理错误日志处理方法
2021/06/30 SQL Server
Android超详细讲解组件ScrollView的使用
2022/03/31 Java/Android
Go获取两个时区的时间差
2022/04/20 Golang
Python创建SQL数据库流程逐步讲解
2022/09/23 Python