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实现读取目录所有文件的文件名并保存到txt文件代码
Nov 22 Python
12步入门Python中的decorator装饰器使用方法
Jun 20 Python
python+opencv实现动态物体追踪
Jan 09 Python
python 信息同时输出到控制台与文件的实例讲解
May 11 Python
ubuntu17.4下为python和python3装上pip的方法
Jun 12 Python
python之信息加密题目详解
Jun 26 Python
Python使用正则表达式分割字符串的实现方法
Jul 16 Python
对python中的*args与**kwgs的含义与作用详解
Aug 28 Python
Python目录和文件处理总结详解
Sep 02 Python
python中的split()函数和os.path.split()函数使用详解
Dec 21 Python
Python新手学习函数默认参数设置
Jun 03 Python
python进行OpenCV实战之画图(直线、矩形、圆形)
Aug 27 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
DOTA2 无惧惊涛骇浪 昆卡大型水友攻略
2020/04/20 DOTA
SESSION信息保存在哪个文件目录下以及能够用来保存什么类型的数据
2012/06/17 PHP
Drupal简体中文语言包安装教程
2014/09/27 PHP
浅析PHP7新功能及语法变化总结
2016/06/17 PHP
yii使用bootstrap分页样式的实例
2017/01/17 PHP
php提高脚本性能的4个技巧
2020/08/18 PHP
jQuery Tools tooltip使用说明
2012/07/14 Javascript
js中flexible.js实现淘宝弹性布局方案
2020/06/23 Javascript
用Vue.extend构建消息提示组件的方法实例
2017/08/08 Javascript
微信小程序实现点击按钮修改view标签背景颜色功能示例【附demo源码下载】
2017/12/06 Javascript
jQuery NProgress.js加载进度插件的简单使用方法
2018/01/31 jQuery
详解如何使用babel进行es6文件的编译
2018/05/29 Javascript
微信小程序开发实现的选项卡(窗口顶部/底部TabBar)页面切换功能图文详解
2019/05/14 Javascript
微信小程序实现点击空白隐藏的方法示例
2019/08/13 Javascript
Layui之table中的radio在切换分页时无法记住选中状态的解决方法
2019/09/02 Javascript
vue中使用element组件时事件想要传递其他参数的问题
2019/09/18 Javascript
vue+layui实现select动态加载后台数据的例子
2019/09/20 Javascript
解决ant Design中this.props.form.validateFields未执行的问题
2020/10/27 Javascript
[03:44]2014DOTA2国际邀请赛 71专访:DK战队赛前讨论视频遭泄露
2014/07/13 DOTA
用Python编写简单的微博爬虫
2016/03/04 Python
python 去除txt文本中的空格、数字、特定字母等方法
2018/07/24 Python
Python 隐藏输入密码时屏幕回显的实例
2019/02/19 Python
Python+threading模块对单个接口进行并发测试
2019/06/25 Python
Django的用户模块与权限系统的示例代码
2019/07/24 Python
PYTHON绘制雷达图代码实例
2019/10/15 Python
网站域名和主机:Domain.com
2019/04/01 全球购物
村干部培训班主持词
2014/03/28 职场文书
2014年教师节讲话稿5篇
2014/09/10 职场文书
乡镇党的群众路线教育实践活动领导班子对照检查材料
2014/09/25 职场文书
警示教育观后感
2015/06/17 职场文书
薪资证明范本
2015/06/19 职场文书
巴黎圣母院读书笔记
2015/06/26 职场文书
普希金的诗歌赏析(3首)
2019/08/20 职场文书
如何用python识别滑块验证码中的缺口
2021/04/01 Python
Javascript使用integrity属性进行安全验证
2021/11/07 Javascript
关于ObjectUtils.isEmpty() 和 null 的区别
2022/02/28 Java/Android