AutoRS/main.py
sairate 58d6e90c39 feat: 添加学生成绩排行榜功能
- 新增 app.py 和 main.py 文件,实现学生成绩排行榜功能
- 添加 CSV 文件处理逻辑,支持成绩数据导入
- 实现成绩排行榜的图形化展示,包括搜索、重新加载等功能
- 新增成绩统计和可视化功能- 添加 .idea 相关配置文件,配置项目环境和样式
2025-05-24 14:33:59 +08:00

43 lines
1.2 KiB
Python

import csv
import tkinter as tk
from tkinter import ttk, messagebox
def process_csv(filename):
with open(filename, 'r') as csvfile:
contents = csv.DictReader(csvfile)
infos=list(contents)
infos=sorted(infos, key=lambda x:int(x['成绩']),reverse=True)
return infos
window = tk.Tk()
window.title('学生成绩排行榜')
window.geometry('500x400')
window.configure(bg='#f0f4f7')
# 设置统一字体
style = ttk.Style()
style.configure('Treeview', font=('华文行楷', 12), rowheight=28)
style.configure('Treeview.Heading', font=('华文行楷', 13, 'bold'))
# 标题标签
title_label = tk.Label(window, text="学生成绩排行榜", bg='#f0f4f7', fg='#336699',font=('华文行楷', 20, 'bold'))
title_label.pack(pady=15)
# 表格
columns = ('姓名', '成绩')
tree = ttk.Treeview(window, columns=columns, show='headings', height=12)
tree.heading('姓名', text='姓名')
tree.heading('成绩', text='成绩')
tree.column('姓名', anchor='center', width=200)
tree.column('成绩', anchor='center', width=100)
infos = process_csv('score.csv')
for info in infos:
tree.insert('', tk.END, values=(info['姓名'], info['成绩']))
tree.pack(pady=10)
# 运行主窗口
window.mainloop()