用python写一段代码,实现校运动会成绩管理系统,利用Tkinter实现窗口操作。 该系统可以录入校运动会全部运动项目的成绩,输出得分,统计各个学院排名情况,项目包括 50 米、100 米、200 米、400 米、跳高、立定跳远、铅球。学院包括001,002到008,可以以图形的形式输出每个学院的各项目得分情况。可以修改各个学院的数据,删除数据。
时间: 2024-03-12 10:43:42 浏览: 161
好的,我可以给您提供一份基础代码,供您参考:
```
import tkinter as tk
import pandas as pd
# 创建主窗口
root = tk.Tk()
root.title("校运动会成绩管理系统")
# 创建数据结构
data = {
"001": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"002": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"003": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"004": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"005": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"006": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"007": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0},
"008": {"50m": 0, "100m": 0, "200m": 0, "400m": 0, "跳高": 0, "立定跳远": 0, "铅球": 0}
}
# 创建数据表格
df = pd.DataFrame(data)
# 创建数据录入窗口
def input_data():
input_window = tk.Toplevel(root)
input_window.title("数据录入")
input_window.geometry("300x300")
# 创建文本框和标签
tk.Label(input_window, text="学院:").grid(row=0, column=0)
tk.Label(input_window, text="项目:").grid(row=1, column=0)
tk.Label(input_window, text="成绩:").grid(row=2, column=0)
college_var = tk.StringVar()
project_var = tk.StringVar()
score_var = tk.StringVar()
college_entry = tk.Entry(input_window, textvariable=college_var)
project_entry = tk.Entry(input_window, textvariable=project_var)
score_entry = tk.Entry(input_window, textvariable=score_var)
college_entry.grid(row=0, column=1)
project_entry.grid(row=1, column=1)
score_entry.grid(row=2, column=1)
# 创建确认按钮
def confirm():
college = college_var.get()
project = project_var.get()
score = int(score_var.get())
data[college][project] = score
df = pd.DataFrame(data)
input_window.destroy()
tk.Button(input_window, text="确认", command=confirm).grid(row=3, column=1)
# 创建数据输出窗口
def output_data():
output_window = tk.Toplevel(root)
output_window.title("数据输出")
output_window.geometry("800x400")
# 创建表格
table = tk.Text(output_window)
table.insert("end", df.to_string())
table.pack()
# 创建排名统计窗口
def rank_data():
rank_window = tk.Toplevel(root)
rank_window.title("排名统计")
rank_window.geometry("800x400")
# 创建排名表格
rank_df = pd.DataFrame(columns=["学院", "得分"])
for college in data:
rank_df.loc[len(rank_df)] = [college, sum(data[college].values())]
rank_df = rank_df.sort_values(by=["得分"], ascending=False)
# 创建表格
table = tk.Text(rank_window)
table.insert("end", rank_df.to_string(index=False))
table.pack()
# 创建数据修改窗口
def modify_data():
modify_window = tk.Toplevel(root)
modify_window.title("数据修改")
modify_window.geometry("300x300")
# 创建文本框和标签
tk.Label(modify_window, text="学院:").grid(row=0, column=0)
tk.Label(modify_window, text="项目:").grid(row=1, column=0)
tk.Label(modify_window, text="成绩:").grid(row=2, column=0)
college_var = tk.StringVar()
project_var = tk.StringVar()
score_var = tk.StringVar()
college_entry = tk.Entry(modify_window, textvariable=college_var)
project_entry = tk.Entry(modify_window, textvariable=project_var)
score_entry = tk.Entry(modify_window, textvariable=score_var)
college_entry.grid(row=0, column=1)
project_entry.grid(row=1, column=1)
score_entry.grid(row=2, column=1)
# 创建确认按钮
def confirm():
college = college_var.get()
project = project_var.get()
score = int(score_var.get())
data[college][project] = score
df = pd.DataFrame(data)
modify_window.destroy()
tk.Button(modify_window, text="确认", command=confirm).grid(row=3, column=1)
# 创建数据删除窗口
def delete_data():
delete_window = tk.Toplevel(root)
delete_window.title("数据删除")
delete_window.geometry("300x300")
# 创建文本框和标签
tk.Label(delete_window, text="学院:").grid(row=0, column=0)
tk.Label(delete_window, text="项目:").grid(row=1, column=0)
college_var = tk.StringVar()
project_var = tk.StringVar()
college_entry = tk.Entry(delete_window, textvariable=college_var)
project_entry = tk.Entry(delete_window, textvariable=project_var)
college_entry.grid(row=0, column=1)
project_entry.grid(row=1, column=1)
# 创建确认按钮
def confirm():
college = college_var.get()
project = project_var.get()
data[college][project] = 0
df = pd.DataFrame(data)
delete_window.destroy()
tk.Button(delete_window, text="确认", command=confirm).grid(row=2, column=1)
# 创建按钮
tk.Button(root, text="录入数据", command=input_data).grid(row=0, column=0)
tk.Button(root, text="输出数据", command=output_data).grid(row=1, column=0)
tk.Button(root, text="排名统计", command=rank_data).grid(row=2, column=0)
tk.Button(root, text="修改数据", command=modify_data).grid(row=3, column=0)
tk.Button(root, text="删除数据", command=delete_data).grid(row=4, column=0)
# 运行主循环
root.mainloop()
```
这份代码实现了数据录入、输出、排名统计、修改和删除等基本功能,并且使用了Pandas库来实现数据的存储和处理。您可以根据自己的需求进行修改和完善。
阅读全文