python+tkinter学生管理系统

简介: python+tkinter学生管理系统版权声明:原创转载无说明出处必究 https://blog.csdn.net/qq1123642601/article/details/90760485 ​from tkinter import *from tkinter.

python+tkinter学生管理系统
版权声明:原创转载无说明出处必究 https://blog.csdn.net/qq1123642601/article/details/90760485

 


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)

 

作者:WF帆少
来源:CSDN
原文:https://blog.csdn.net/qq1123642601/article/details/90760485
版权声明:本文为博主原创文章,转载请附上博文链接!

相关文章
|
3天前
|
机器学习/深度学习 Ubuntu 数据挖掘
Ubuntu系统部署Anaconda环境及Python语言的详细流程
以上就是在Ubuntu系统中安装Anaconda环境及Python语言的详细流程。Anaconda为Python科学计算提供了便捷的管理方式,帮助用户轻松处理不同项目之间依赖管理的复杂性。通过以上步骤,你现在应该有了一个完全可用的Anaconda环境,可以开始在Ubuntu上进行Python编程和数据科学项目的探索了。
14 5
|
8天前
|
Python
python tkinter 实现简易秒表计时器
python tkinter 实现简易秒表计时器
21 1
|
10天前
|
数据可视化 文件存储 Python
【python】python基于tkinter的学生成绩管理系统(源码+数据文件)【独一无二】(二)
【python】python基于tkinter的学生成绩管理系统(源码+数据文件)【独一无二】(二)
|
11天前
|
存储 数据可视化 Python
【python】python tkinter 计算器GUI版本(模仿windows计算器 源码)【独一无二】
【python】python tkinter 计算器GUI版本(模仿windows计算器 源码)【独一无二】
|
1天前
|
机器学习/深度学习 Ubuntu 数据挖掘
揭秘:Ubuntu系统下部署Anaconda环境及Python语言的终极指南!跟随这一步步神秘流程,解锁编程大师的秘密武器!
【8月更文挑战第19天】在Ubuntu中部署Anaconda环境与Python相当直观。首先需从官网下载Linux版安装包。接着,在终端依次执行命令:添加Anaconda清华镜像源至软件源列表,更新软件包信息,然后安装Anaconda。安装后可通过`anaconda --version`验证。使用`anaconda create -n myenv python=3.8`创建名为“myenv”的环境并指定Python 3.8版本。
10 0
|
8天前
|
Linux Python
Linux——删除系统python导致yum无法使用
Linux——删除系统python导致yum无法使用
20 0
|
9天前
|
存储 数据可视化 数据挖掘
【Python】Tkinter电器销售有限公司销售数据分析(源码)【独一无二】
【Python】Tkinter电器销售有限公司销售数据分析(源码)【独一无二】
|
9天前
|
存储 数据可视化 UED
【Python】Tkinter超市商品选购系统 [简易版] (源码)【独一无二】
【Python】Tkinter超市商品选购系统 [简易版] (源码)【独一无二】
|
9天前
|
存储 Python
【python】python生活管理费系统(源码+论文)【独一无二】
【python】python生活管理费系统(源码+论文)【独一无二】
|
10天前
|
存储 Python
【python】python基于tkinter的学生成绩管理系统(源码+数据文件)【独一无二】(一)
【python】python基于tkinter的学生成绩管理系统(源码+数据文件)【独一无二】(一)