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中返回字典键的值的values()方法使用
May 22 Python
详解Python中time()方法的使用的教程
May 22 Python
Python cookbook(数据结构与算法)实现对不原生支持比较操作的对象排序算法示例
Mar 15 Python
Python实现高斯函数的三维显示方法
Dec 29 Python
在python中实现强制关闭线程的示例
Jan 22 Python
python+numpy按行求一个二维数组的最大值方法
Jul 09 Python
python3-flask-3将信息写入日志的实操方法
Nov 12 Python
wxPython实现画图板
Aug 27 Python
python中提高pip install速度
Feb 14 Python
利用matplotlib为图片上添加触发事件进行交互
Apr 23 Python
Python Spyder 调出缩进对齐线的操作
Feb 26 Python
解决pytorch 模型复制的一些问题
Mar 03 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中两种缩放图片的函数,为图片添加水印
2013/06/14 PHP
checkbox 多选框 联动实现代码
2008/10/22 Javascript
javascript高级学习笔记整理
2011/08/14 Javascript
使用Math.floor与Math.random取随机整数的方法详解
2013/05/07 Javascript
JS 对象属性相关(检查属性、枚举属性等)
2015/04/05 Javascript
javascript实现列表切换效果
2016/05/02 Javascript
Bootstrap教程JS插件弹出框学习笔记分享
2016/05/17 Javascript
Angular 4.x中表单Reactive Forms详解
2017/04/25 Javascript
关于vue-router路径计算问题
2017/05/10 Javascript
ionic3 懒加载
2017/08/16 Javascript
多个vue子路由文件自动化合并的方法
2019/09/03 Javascript
js实现左右轮播图
2020/01/09 Javascript
antd Select下拉菜单动态添加option里的内容操作
2020/11/02 Javascript
python共享引用(多个变量引用)示例代码
2013/12/04 Python
Python中使用装饰器来优化尾递归的示例
2016/06/18 Python
Python入门_浅谈for循环、while循环
2017/05/16 Python
解决pycharm无法识别本地site-packages的问题
2018/10/13 Python
Django框架基础模板标签与filter使用方法详解
2019/07/23 Python
利用python实现AR教程
2019/11/20 Python
Django 拼接两个queryset 或是两个不可以相加的对象实例
2020/03/28 Python
django使用channels实现通信的示例
2020/10/19 Python
网页中的电话号码如何实现一键直呼效果_附示例
2016/03/15 HTML / CSS
Myprotein丹麦官网:欧洲第一运动营养品牌
2019/04/15 全球购物
新浪网技术部笔试题
2016/08/26 面试题
档案接收函
2014/01/13 职场文书
会计电算化学生个人的自我评价
2014/02/08 职场文书
个人简历求职信范文
2015/03/20 职场文书
材料员岗位职责范本
2015/04/11 职场文书
质检员工作总结2015
2015/04/25 职场文书
高中班主任寄语
2019/06/21 职场文书
jquery插件实现代码雨特效
2021/04/24 jQuery
Python手拉手教你爬取贝壳房源数据的实战教程
2021/05/21 Python
如何将JavaScript将数组转为树形结构
2021/06/02 Javascript
OpenCV-Python实现人脸美白算法的实例
2021/06/11 Python
AJAX引擎原理以及XmlHttpRequest对象的axios、fetch区别详解
2022/04/09 Javascript
MySQL串行化隔离级别(间隙锁实现)
2022/06/16 MySQL