一、问题描述
# -*- coding: utf-8 -*-
# @Create Time : 2024/4/22 13:38
# @Edit Time : 2024/4/23 10:59
# @Author : Tim
# @File : UI.py
# @Software : PyCharm
import re
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
import pandas as pd
import threading
# 新增曲目列表
SONG_NAMES = ["歌曲A", "歌曲B", "歌曲C"]
# 存储每首歌曲对应的评分
SONG_SCORES = {}
def center_window(window, width, height):
screen_width = window.winfo_screenwidth()
screen_height = window.winfo_screenheight()
x = (screen_width // 2) - (width // 2)
y = (screen_height // 2) - (height // 2)
window.geometry(f"{width}x{height}+{x}+{y}")
def is_valid_integer(text):
return re.match(r'^\d+$', text) and 1 <= int(text) <= 120
def save_to_excel_thread(name, age, gender, score1, score2, score3):
data = {
"姓名": [name],
"年龄": [age],
"性别": [gender],
"歌曲A": [score1],
"歌曲B": [score2],
"歌曲C": [score3]
}
try:
df = pd.DataFrame(data)
# 这里假设默认当前工作目录是可写的,更健壮的实现应考虑指定路径或检查权限
df.to_excel('data.xlsx', index=False)
messagebox.showinfo("成功", "数据已保存到Excel文件")
except Exception as e:
messagebox.showerror("错误", f"保存失败: {e}")
def save_to_excel(name_entry, age_entry, gender_comb