python+tkinter实现学生管理系统

 更新时间:2019年08月20日 14:23:18   作者:WF帆少  
这篇文章主要为大家详细介绍了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中关于集合的介绍与常规操作解析

    Python除了List、Tuple、Dict等常用数据类型外,还有一种数据类型叫做集合(set),集合的最大特点是:集合里边的元素是不可重复的并且集合内的元素还是无序的
    2021-09-09
  • 将pip源更换到国内镜像的详细步骤

    将pip源更换到国内镜像的详细步骤

    这篇文章主要介绍了将pip源更换到国内镜像的详细步骤,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-04-04
  • 基于Keras中Conv1D和Conv2D的区别说明

    基于Keras中Conv1D和Conv2D的区别说明

    这篇文章主要介绍了基于Keras中Conv1D和Conv2D的区别说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-06-06
  • 解决Windows下PowerShell无法进入Python虚拟环境问题

    解决Windows下PowerShell无法进入Python虚拟环境问题

    这篇文章主要介绍了解决Windows下PowerShell无法进入Python虚拟环境问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • 2021年最新版Python安装及使用教学

    2021年最新版Python安装及使用教学

    今天带大家学习的是Python的相关知识,文章围绕着Python的安装及使用展开,文中有非常详细的图文示例及介绍,需要的朋友可以参考下
    2021-06-06
  • Python如何处理大数据?3个技巧效率提升攻略(推荐)

    Python如何处理大数据?3个技巧效率提升攻略(推荐)

    这篇文章主要介绍了Python如何处理大数据?3个技巧效率提升攻略,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-04-04
  • django多文件上传,form提交,多对多外键保存的实例

    django多文件上传,form提交,多对多外键保存的实例

    今天小编就为大家分享一篇django多文件上传,form提交,多对多外键保存的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-08-08
  • python通过elixir包操作mysql数据库实例代码

    python通过elixir包操作mysql数据库实例代码

    这篇文章主要介绍了python通过elixir包操作mysql数据库,分享了相关代码示例,小编觉得还是挺不错的,具有一定借鉴价值,需要的朋友可以参考下
    2018-01-01
  • python排序算法之希尔排序

    python排序算法之希尔排序

    这篇文章主要介绍了python排序算法之希尔排序,希尔排序,又叫“缩小增量排序”,是对插入排序进行优化后产生的一种排序算法,需要的朋友可以参考下
    2023-04-04
  • python获取txt文件词向量过程详解

    python获取txt文件词向量过程详解

    这篇文章主要介绍了python获取txt文件词向量过程详解,如何读取完整的大文件,而不会出现内存不足memery error等问题,将读取出来的文件,保存为npy文件,根据词找到对应的向量,需要的朋友可以参考下
    2019-07-07

最新评论