Gui编程学生成绩管理系统

仅供参考和学习  作者:黎爬爬

目录

 写在前面

简单的Gui界面(没有用到数据库)

tkinter与sqlite3数据库结合制作的Gui界面


 写在前面

了解一下内容 你需要提前学会基本的tkinter语法 和 sqlite基本操作

安装库:

pip install tkinter

pip install sqlite3

调用库 

from tkinter import *

import sqlite3

简单的Gui界面(没有用到数据库)

from tkinter import *
from tkinter import messagebox
class CalStdScore:
    def __init__(self):
        win=Tk()
        win.geometry('256x192')
        win.title('统计学生成绩')

        lblCpp=Label(win,text='C++程序设计')
        lblCpp.grid(row=0,column=0,padx=5,pady=5,sticky='e')
        self.VCppScore=IntVar()
        entCpp=Entry(win,width=15,textvariable=self.VCppScore)
        entCpp.grid(row=0,column=1,padx=5,pady=5,sticky='w')


        lblPython=Label(win,text='Python程序设计')
        lblPython.grid(row=1,column=0,padx=5,pady=5,sticky='e')
        self.VPythonScore=IntVar()
        entPython=Entry(win,width=15,textvariable=self.VPythonScore)
        entPython.grid(row=1,column=1,padx=5,pady=5,sticky='w')

        lblJave=Label(win,text='Jave程序设计')
        lblJave.grid(row=2,column=0,padx=5,pady=5,sticky='e')
        self.VJaveScore=IntVar()
        entJave=Entry(win,width=15,textvariable=self.VJaveScore)
        entJave.grid(row=2,column=1,padx=5,pady=5,sticky='w')

        btnCalculace=Button(win,text='统计学生成绩',command=self.Calculate,width=15,height=1)
        btnCalculace.grid(row=3,column=0,columnspan=2,pady=5)

        win.mainloop()
    def Calculate(self):
        try:
            xCppScore=int(self.VCppScore.get())
            xPythonScore=int(self.VPythonScore.get())
            xJavaScore=int(self.VJaveScore.get())
            xAvgScore=(xCppScore+xPythonScore+xJavaScore)//3
            xMaxScore=max(xCppScore,xPythonScore,xJavaScore)
            xMinScore=min(xCppScore,xPythonScore,xJavaScore)
            strl="平均成绩:"+str(xAvgScore)+'\n'\
                +"最高成绩:"+str(xMaxScore)+'\n'\
                +"最低成绩"+str(xMinScore)
            messagebox.showinfo(title='统计成绩',message=strl)
        except:
            messagebox.showinfo(title='提示',message='输入错误,重新输入')
CalStdScore()


tkinter与sqlite3数据库结合制作的Gui界面

包含  创建 录入 删除 查询 查找 关闭 等基本内容

.db数据库文件 建议用Vscode sqlite3viwer打开

from tkinter import *
import sqlite3
import tkinter
class student:
    def __init__(self,win):
        self.conn=sqlite3.connect(r"test.db") #连接数据库
        self.cur=self.conn.cursor() #创建游标
        self.win=win
        win.geometry('520x520')
        win.title('学生信息管理 作者:黎爬爬')
        L1=Label(win) #头
        L1.pack()
        
        self.id=IntVar()
        self.name=StringVar()
        self.sex=StringVar()
        self.age=IntVar()
        self.class_=StringVar()
        Label(L1,text='学生管理平台',font=('黑体',15)).grid(row=0,column=0,columnspan=5,sticky='e')
        
        Label(L1,text='学号').grid(row=1,column=0,sticky='w',padx=5,pady=5)
        Entry(L1,textvariable=self.id,width=10).grid(row=1,column=1,sticky='w',padx=5,pady=5)
        
        Label(L1,text='姓名').grid(row=2,column=0,sticky='w',padx=5,pady=5)
        Entry(L1,textvariable=self.name,width=10).grid(row=2,column=1,sticky='w',padx=5,pady=5)

        Label(L1,text='年龄').grid(row=3,column=0,sticky='w',padx=5,pady=5)
        Entry(L1,textvariable=self.age,width=10).grid(row=3,column=1,sticky='w',padx=5,pady=5)

        Label(L1,text='性别').grid(row=2,column=2,sticky='w',padx=5,pady=5)
        Entry(L1,textvariable=self.sex,width=10).grid(row=2,column=3,sticky='w',padx=5,pady=5)

        Label(L1,text='班级').grid(row=3,column=2,sticky='w',padx=5,pady=5)
        Entry(L1,textvariable=self.class_,width=10).grid(row=3,column=3,sticky='w',padx=5,pady=5)

        Button(L1,text='创建',command=self.create,width=5).grid(row=4,column=0,sticky='w',padx=5,pady=5)
        Button(L1,text='录入',command=self.insert,width=5).grid(row=4,column=1,sticky='w',padx=5,pady=5)
        Button(L1,text='删除',command=self.delete,width=5).grid(row=4,column=2,sticky='w',padx=5,pady=5)
        Button(L1,text='修改',command=self.change,width=5).grid(row=4,column=3,sticky='w',padx=5,pady=5)
        Button(L1,text='查询',command=self.find,width=5).grid(row=4,column=4,sticky='w',padx=5,pady=5)
        Button(L1,text='查看',command=self.findall,width=5).grid(row=4,column=5,sticky='w',padx=5,pady=5)
        Button(L1,text='关闭',command=self.close,width=5).grid(row=4,column=6,sticky='w',padx=5,pady=5)
    

        L2=Label(win,width=500,height=200,relief="sunken")
        
        self.text=Text(L2,width=50,height=30)
        self.text.grid(row=1,column=0,sticky='e')
        L2.pack()
    def create(self):
        sql='''
        create table studentsystem(
        sid char(7) primary key,
        sname varchar(8),
        ssex char(2),
        sage smallint,
        sclass varchar(16));
        '''
        self.cur.execute(sql)
        self.conn.commit()

    def insert(self):
        id=self.id.get()
        name=self.name.get()
        sex=self.sex.get()
        age=self.age.get()
        class_=self.class_.get()

        self.cur.execute("insert into studentsystem values('%s','%s','%s',%d,'%s')"%(id,name,sex,age,class_))
        self.conn.commit()
    
    def delete(self):
        id=self.id.get()
        
        self.cur.execute('delete from studentsystem where sid=%d'%id)
        self.conn.commit()
        
    def change(self):
        name=self.name.get()
        id=self.id.get()
        sex=self.sex.get()
        age=self.age.get()
        class_=self.class_.get()
        sql = 'update studentsystem set sname=?, ssex=?, sage=?, sclass=? where sid=?'
        student_data = (name, sex, age,class_,id)
        self.cur.execute(sql,student_data)
        self.conn.commit()

    def find(self):
        id=self.id.get()
        
        data=self.cur.execute('select * from studentsystem where sid=%s'%id)
        strdata=''
        
        for item in data:
            strdata=strdata+str(item)
        self.text.insert(1.5,strdata)
        self.conn.commit()
        

    def findall(self):
        sql='''
        select * from studentsystem
        '''
        data=self.cur.execute(sql)
        strdata=''
        for item in data:
            strdata=strdata+str(item)
        self.text.insert(1.5,strdata)
        self.conn.commit()
    def close(self):
        self.cur.close()
        self.conn.close()
        win.destroy()
win=Tk()
student(win)
win.mainloop()        

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涡巻ナルト人≥サス

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值