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 相关文章推荐
Django在Win7下的安装及创建项目hello word简明教程
Jul 14 Python
Python中的列表知识点汇总
Apr 14 Python
python 换位密码算法的实例详解
Jul 19 Python
Python学习小技巧总结
Jun 10 Python
python3+selenium实现126邮箱登陆并发送邮件功能
Jan 23 Python
PowerBI和Python关于数据分析的对比
Jul 11 Python
python实现socket+threading处理多连接的方法
Jul 23 Python
Series和DataFrame使用简单入门
Nov 13 Python
Tensorflow tf.dynamic_partition矩阵拆分示例(Python3)
Feb 07 Python
浅析Django 接收所有文件,前端展示文件(包括视频,文件,图片)ajax请求
Mar 09 Python
python爬虫工具例举说明
Nov 30 Python
Python中with上下文管理协议的作用及用法
Mar 18 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用星号隐藏部份用户名、身份证、IP、手机号等实例
2014/04/08 PHP
ucenter通信原理分析
2015/01/09 PHP
php实现有趣的人品测试程序实例
2015/06/08 PHP
js的2种继承方式详解
2014/03/04 Javascript
JavaScript图片轮播代码分享
2015/07/31 Javascript
easyui window refresh 刷新两次的解决方法(推荐)
2016/05/18 Javascript
AngularGauge 属性解析详解
2016/09/06 Javascript
javascript循环链表之约瑟夫环的实现方法
2017/01/16 Javascript
Bootstrap输入框组件简单实现代码
2017/03/06 Javascript
Zepto实现密码的隐藏/显示
2017/04/07 Javascript
jQuery plugin animsition使用小结
2017/09/14 jQuery
浅谈react-router HashRouter和BrowserRouter的使用
2017/12/29 Javascript
Vue 路由切换时页面内容没有重新加载的解决方法
2018/09/01 Javascript
JS实现图片切换效果
2018/11/17 Javascript
Vue 动态添加路由及生成菜单的方法示例
2019/06/20 Javascript
Vue项目中Api的组织和返回数据处理的操作
2019/11/04 Javascript
JavaScript中的this原理及6种常见使用场景详解
2020/02/14 Javascript
ES6扩展运算符和rest运算符用法实例分析
2020/05/23 Javascript
[06:53]2018DOTA2国际邀请赛寻真——为复仇而来的Newbee
2018/08/15 DOTA
Python实现的监测服务器硬盘使用率脚本分享
2014/11/07 Python
django小技巧之html模板中调用对象属性或对象的方法
2018/11/30 Python
如何通过python画loss曲线的方法
2019/06/26 Python
python获取array中指定元素的示例
2019/11/26 Python
Python 时间戳之获取整点凌晨时间戳的操作方法
2020/01/28 Python
Python3 中sorted() 函数的用法
2020/03/24 Python
使用Pycharm分段执行代码
2020/04/15 Python
python安装后的目录在哪里
2020/06/21 Python
css3.0新属性效果在ie下的解决方案
2010/05/10 HTML / CSS
关于css中margin的值和垂直外边距重叠问题
2020/10/27 HTML / CSS
Lands’ End官网:经典的美国生活方式品牌
2016/08/14 全球购物
香港钟表珠宝首饰商城:OneMallTime网摩间
2016/10/14 全球购物
大学迎新标语
2014/06/26 职场文书
咖啡店创业计划书范文
2014/09/15 职场文书
大学生考试作弊检讨书1000字
2014/10/14 职场文书
爱牙日宣传活动总结
2015/02/05 职场文书
nginx lua 操作 mysql
2022/05/15 Servers