程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[Python] a self-made student management system with GUI

編輯:Python

I've been studying recently Python Of tkinter Of gui library , So I decided to make a gui Version of the student management system program
The original code is :https://blog.csdn.net/weixin_43321726/article/details/103569640
This is my code , It took half a day to knock it out

import tkinter as tk
from PIL import Image, ImageTk
from tkinter.messagebox import showinfo
import json
import time
import os
import cure
root = tk.Tk()
root.title(' Student information management system ')
# background 
canvas = tk.Canvas(root, width=1200,height=699,bd=0, highlightthickness=0)
imgpath = r'D:\py\vs\Python_package\wordpress.jpg'
img = Image.open(imgpath)
photo = ImageTk.PhotoImage(img)
canvas.create_image(700, 500, image=photo)
canvas.pack()
canvas.create_text(600,350,text=' huan To meet send use learn raw Letter Rest tube The reason is system system ',font=(' Microsoft YaHei ',26))
def post(name,math,chinese,english,win1):
name = name.get()
math = math.get()
chinese = chinese.get()
english = english.get()
try:
total = int(math) + int(chinese) + int(english)
except:
tk.messagebox.showerror('oh Something went wrong ',' Submit failed , Please enter the correct grade ')
btn1cmd()
else:
grade_list = {
'name':name,'math':math,'chinese':chinese,'english':english,'total':total}
print([name,math,chinese,english,total])
print(' full name :{}\t Math scores :{}\t Chinese achievement :{}\t English scores : {}'.format(name,math,chinese,english,total))
with open('Python_package\grade list.txt','a',encoding='utf-8') as f:
f.write('\n'+str(grade_list))
tk.messagebox.showinfo(' Submit successfully ',' Submit successfully , About to return to the home page ')
time.sleep(3)
win1.destroy()
pass
def find(name):
name = name.get()
with open('Python_package\grade list.txt',encoding='utf-8') as f:
lines = f.readlines()
for i in range(len(lines)):
if name in lines[i]:
tk.messagebox.showinfo(' eureka ',lines[i])
break
else:
tk.messagebox.showerror('error',' This student does not exist , Please re-enter ')
def delGakuse(name):
name = name.get()
with open('Python_package\grade list.txt',encoding='utf-8') as f:
lines = f.readlines()
for i in lines:
if (eval(i))['name'] == name:
tk.messagebox.showinfo('OK',' Successfully deleted information ')
conversion('Python_package\grade list.txt',lines.index(i),'')
break
else:
tk.messagebox.showerror('error',' This student does not exist ')
def edit(name):
name = name.get()
with open('Python_package\grade list.txt',encoding='utf-8') as f:
lines = f.readlines()
for i in range(len(lines)):
if name in lines[i]:
def a(r,a):# Too lazy to name 
mg = ''
mg += str(r.get())
mathematics
edit = tk.Toplevel()
edit.title(' Please select the content you want to modify ')
r=tk.IntVar()
r.set(2)
tk.Radiobutton(edit,text=' mathematics ',value=1,variable=r).pack()
tk.Radiobutton(edit,text=' Chinese language and literature ',value=2,variable=r).pack()
tk.Radiobutton(edit,text=' English ',value=3,variable=r).pack()
a=tk.StringVar()
a.set(' Enter the score ')
tk.Entry(width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=a, validate="focus").pack()
tk.Button(edit,text=' modify ',command=lambda: a(r,a)).pack()
conversion('Python_package\grade list.txt',i,'')
break
else:
tk.messagebox.showerror('error',' This student does not exist , Please re-enter ')
def btn1cmd():
win1 = tk.Toplevel()
win1.title(' New student information ')
name = tk.StringVar()
name.set(' Please enter a name ')
tk.Entry(win1, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=name, validate="focus").pack()
math = tk.StringVar()
math.set(' Please enter the math score ')
tk.Entry(win1, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=math, validate="focus").pack()
chinese = tk.StringVar()
chinese.set(' Please input Chinese score ')
tk.Entry(win1, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=chinese, validate="focus").pack()
english = tk.StringVar()
english.set(' Please enter your English score ')
tk.Entry(win1, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=english, validate="focus").pack()
tk.Button(win1,text=' Submit ',command=lambda: post(name,math,chinese,english,win1)).pack()
def btn2cmd():
with open('Python_package\grade list.txt',encoding='utf-8') as f:
grade_list = f.read()
win2 = tk.Toplevel()
win2.title(' Show all information ')
tk.Label(win2,text=grade_list).pack()
def btn3cmd():
win3 = tk.Toplevel()
win3.title(' Search for student information ')
name = tk.StringVar()
name.set(' Please enter the name of the student you want to query ')
tk.Entry(win3, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=name, validate="focus").pack()
tk.Button(win3,text=' lookup ',command=lambda: find(name)).pack()
def btn4cmd():
win4 = tk.Toplevel()
win4.title(' Delete student information ')
name = tk.StringVar()
name.set(' Please enter the name of the student you want to delete ')
tk.Entry(win4, width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=name, validate="focus").pack()
tk.Button(win4,text=' Delete ',command=lambda: delGakuse(name)).pack()
def btn5cmd():
win5 = tk.Toplevel()
win5.title(' Modify student information ')
name = tk.StringVar()
name.set(' Please enter the name of the student you want to query ')
tk.Entry(win5,width=30, borderwidth=1, fg="#f00",insertwidth=1,
insertbackground="#333", state=tk.NORMAL,
textvariable=name, validate="focus").pack()
tk.Button(win5,text=' Inquire about ',command=lambda: edit(name)).pack()
def start(canvas):
canvas.pack_forget()
theLabel = tk.Label(root,text=''' ****************************** Welcome to use 【 Student information management system 】 ****************************** ''')
root.geometry('700x500')
theLabel.pack()
tk.Button(root,text="1. New student information ",command=btn1cmd).pack()
tk.Button(root,text="2. Show all information ",command=lambda: btn2cmd()).pack()
tk.Button(root,text="3. Search for student information ",command=btn3cmd).pack()
tk.Button(root,text="4. Delete student information ",command=btn4cmd).pack()
tk.Button(root,text="5. Modify student information ",command=btn5cmd).pack()
startBtn = tk.Button(root, text = "Start!",anchor = tk.W,command=lambda: start(canvas))
startBtn.configure(width = 10, activebackground = "#33B5E5", relief = tk.SOLID,bg='pink')
button1_window = canvas.create_window(560, 400,window=startBtn,anchor='nw')
def on_closing():
if tk.messagebox.askokcancel("Quit", ' Do you really want to leave ~QAQ'):
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

There is a library made by myself , Easy to use when writing code , Download address
https://gitee.com/cat_ci/codes/1y2sqou3zvjbtx6nk4dl896
If get When you get what you want , Don't forget to leave a praise ~


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved