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写asp详细讲解
Dec 16 Python
利用python操作SQLite数据库及文件操作详解
Sep 22 Python
手把手教你python实现SVM算法
Dec 27 Python
一道python走迷宫算法题
Jan 22 Python
Python 新建文件夹与复制文件夹内所有内容的方法
Oct 27 Python
Python如何实现转换URL详解
Jul 02 Python
python实现word文档批量转成自定义格式的excel文档的思路及实例代码
Feb 21 Python
判断Threading.start新线程是否执行完毕的实例
May 02 Python
Python中如何引入第三方模块
May 27 Python
Python sqlalchemy时间戳及密码管理实现代码详解
Aug 01 Python
详解python tcp编程
Aug 24 Python
python 三边测量定位的实现代码
Apr 22 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 mssql 时间格式问题
2009/01/13 PHP
fleaphp常用方法分页之Pager使用方法
2011/04/23 PHP
php中的三元运算符使用说明
2011/07/03 PHP
如何做到打开一个页面,过几分钟自动转到另一页面
2007/04/20 Javascript
form中限制文本字节数js代码
2007/06/10 Javascript
JS操作Cookies包括(读取添加与删除)
2012/12/26 Javascript
使用Java实现简单的server/client回显功能的方法介绍
2013/05/03 Javascript
JS测试显示屏分辨率以及屏幕尺寸的方法
2013/11/22 Javascript
JavaScript统计网站访问次数的实现代码
2015/11/18 Javascript
jQuery实现分隔条左右拖动功能
2015/11/21 Javascript
AngularJS表格样式简单设置方法示例
2017/03/03 Javascript
Javascript实现倒计时时差效果
2017/05/18 Javascript
深入理解node.js http模块
2018/01/24 Javascript
谈谈React中的Render Props模式
2018/12/06 Javascript
详解element-ui设置下拉选择切换必填和非必填
2019/06/17 Javascript
javascript实现前端成语点击验证
2020/06/24 Javascript
[00:14]护身甲盾
2019/03/06 DOTA
python处理数据,存进hive表的方法
2018/07/04 Python
Python实现图片转字符画的代码实例
2019/02/22 Python
Python Opencv提取图片中某种颜色组成的图形的方法
2019/09/19 Python
使用css如何制作时间ICON方法实践
2012/11/12 HTML / CSS
Johnston & Murphy官网: 约翰斯顿·墨菲牛津总统鞋
2018/01/09 全球购物
质检部经理岗位职责
2014/02/19 职场文书
亲子读书活动方案
2014/02/22 职场文书
元旦促销方案
2014/03/15 职场文书
实习评语大全
2014/04/26 职场文书
化妆品活动策划方案
2014/05/23 职场文书
青年文明号口号
2014/06/17 职场文书
2014年班主任工作总结
2014/11/08 职场文书
2014年小班保育员工作总结
2014/12/23 职场文书
升职自我推荐信范文
2015/03/25 职场文书
迁徙的鸟观后感
2015/06/09 职场文书
小学二年级语文教学反思
2016/03/03 职场文书
营销策划分析:怎么策划才能更好销量产品?
2019/09/04 职场文书
PostgreSQL数据库创建并使用视图以及子查询
2022/04/11 PostgreSQL
SQL Server使用CROSS APPLY与OUTER APPLY实现连接查询
2022/05/25 SQL Server