首页 > 其他分享 >基于tkinter的学生信息管理系统设计与实现

基于tkinter的学生信息管理系统设计与实现

时间:2024-06-12 10:57:23浏览次数:15  
标签:基于 tkinter root height width place 信息管理系统 label root1

一个基于python和tkinter的GUI学生信息管理系统,包括管理员登录以及对学生信息的增删改查,支持上传学生图片以及展示图片,数据库使用的是mysql

项目结构

背景图片

在之前的大佬的代码上做了大幅修改,但是找不到链接了

管理员登录代码

from tkinter import *
from tkinter import messagebox
import tkinter
import pymysql
import main

def linkDB():  # 连接数据库
    db = pymysql.connect(host='localhost',  # 打开数据库连接
                         port=3306,
                         user='root',
                         passwd='123123',
                         db='studentinfo')

    # 使用 cursor() 方法创建一个游标对象cur
    cur = db.cursor(cursor=pymysql.cursors.DictCursor)

    return db, cur

root = tkinter.Tk()
root.resizable(False, False)
root.minsize(450, 350)
root.maxsize(450, 350)
root.title("学生信息管理系统-登录")
root.config(width=450)
root.config(height=350)

screenWidth = root.winfo_screenwidth()
screenHeight = root.winfo_screenheight()
width = 300
height = 160
left = (screenWidth - width) / 2.8
top = (screenHeight - height) / 6
root.geometry("%dx%d+%d+%d" % (width, height, left, top))

# 创建关联字符变量
varUsername = StringVar(root, value='')
varPassword = StringVar(root, value='')
pwd = '1'
def login_check():
    try:
        db, cur = linkDB()
        username = entryUsername.get()
        if(username==''):
            messagebox.showerror('提示', message='请输入账号!')
        else:
            password = entryPassword.get()
            if(password=='1'):
                messagebox.showerror('提示', message='请输入密码!')
            else:
                cur.execute("SELECT password from admin where username = '%s' and Flag = 1;" % username)
                num = 1
                cursor = cur.fetchone()
                db.commit()
                if (num == 1):
                    pwd = cursor['password']
                    print(pwd)
                    if (pwd == password):
                        root.destroy()
                        main.Main()
                    else:
                        messagebox.showerror('提示', message='登录信息有误!')
                else:
                    messagebox.showerror('提示', message='无此账号!')
    except:
        print("未知错误,请联系系统管理员!")

# 创建标签组件
label = Label(root, text="账号:", font=("仿宋 -18"))
label.place(x=60, y=60, height=40, width=80)

label = Label(root, text="密码:", font=("仿宋 -18"))
label.place(x=60, y=110, height=40, width=80)

entryUsername = Entry((root), textvariable=varUsername)
entryUsername.place(x=140, y=60, height=40, width=200)

entryPassword = Entry((root), textvariable=varPassword)
entryPassword.place(x=140, y=110, height=40, width=200)

buttonsel_stu = Button(root, text="登录", bg='lightyellow', font=("仿宋 -18"), command=login_check,relief=GROOVE)
buttonsel_stu.place(x=140, y=180, height=40, width=200)

buttoncancel_stu = Button(root, text="退出", bg='lightyellow', font=("仿宋 -18"), command=root.destroy,relief=GROOVE)
buttoncancel_stu.place(x=140, y=230, height=40, width=200)

root.mainloop()

主界面代码

from tkinter import *
from tkinter import messagebox, ttk
from PIL import Image, ImageTk
import tkinter
import pymysql
from tkinter import filedialog
import tkinter as tk

def linkDB():  # 连接数据库
    db = pymysql.connect(host='localhost',  # 打开数据库连接
                         port=3306,
                         user='root',
                         passwd='123123',
                         db='studentinfo')

    # 使用 cursor() 方法创建一个游标对象cur
    cur = db.cursor(cursor=pymysql.cursors.DictCursor)

    return db, cur

# 增加学生信息
def insert_stu():  # 录入学生信息

    def upload_file():
        selectFile = tk.filedialog.askopenfilename()  # askopenfilename 1次上传1个;askopenfilenames1次上传多个
        entryImg.insert(0, selectFile)

    root1 = Tk()
    root1.title("录入学生信息")
    root1.config(width=600)
    root1.configure(bg='linen')
    root1.config(height=600)

    # 创建关联字符变量
    varName = StringVar(root1, value='')
    varId = StringVar(root1, value='')
    varSex = StringVar(root1, value='')
    varClass = StringVar(root1, value='')
    varAge = StringVar(root1, value='')
    varImg = StringVar(root1, value='')

    # 创建标签组件
    label = Label(root1, text="姓名:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=30, height=40, width=80)

    label = Label(root1, text="学号:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=80, height=40, width=80)

    label = Label(root1, text="性别:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=130, height=40, width=80)

    # # 创建单选按钮
    # radio_button1 = Tk().Radiobutton(root, text="男", variable=radio_var, value="男")
    # radio_button2 = Tk().Radiobutton(root, text="女", variable=radio_var, value="女")

    label = Label(root1, text="班级:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=180, height=40, width=80)

    label = Label(root1, text="年龄:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=230, height=40, width=80)

    label = Label(root1, text="照片:", bg='linen', font=("仿宋 -18"))
    label.place(x=130, y=280, height=40, width=90)

    # 关联变量
    #    姓名entryName
    #    学号entryId
    #    性别entrySex
    #    班级entryClass
    #    年龄entryAge
    entryName = Entry((root1), textvariable=varName)
    entryName.place(x=200, y=30, height=40, width=200)

    entryId = Entry((root1), textvariable=varId)
    entryId.place(x=200, y=80, height=40, width=200)

    entrySex = Entry((root1), textvariable=varSex)
    entrySex.place(x=200, y=130, height=40, width=200)

    entryClass = Entry((roo

标签:基于,tkinter,root,height,width,place,信息管理系统,label,root1
From: https://blog.csdn.net/weixin_57244254/article/details/139610684

相关文章