-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
95 lines (70 loc) · 2.86 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import tkinter as tk
from tkinter import ttk
import pandas as pd
import datetime
# 创建空的装备列表
selected_equipments = []
def clear_selected_listbox():
global selected_equipments
# public selected_equipments
selected_equipments = []
result_text.delete(1.0, tk.END)
selected_listbox.delete(0, tk.END) # 删除所有选项
# 添加装备到列表
def add_equipment():
global selected_equipments
(equip, level) = (combo_equipment.get(), combo_level.get())
if (equip, level) not in selected_equipments:
selected_equipments.append((equip, level))
selected_listbox.insert(tk.END, (equip, level))
def calculate_materials():
global selected_equipments, total_materials
# 构建筛选条件
conditions = pd.Series(False, index=equipment_data.index)
for (equip, level) in selected_equipments:
conditions = conditions | ((equipment_data['名称'] == equip) & (equipment_data['升级等级'] == level))
selected_equipment = equipment_data[conditions]
# selected_materials = pd.DataFrame(columns=['材料名称', '需要的数量'])
selected_materials = selected_equipment.iloc[:, -2:]
total_materials = selected_materials.groupby('材料名称')['需要的数量'].sum().reset_index()
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, total_materials.to_string(index=False))
def save_instructions():
global total_materials
ts = datetime.datetime.now().timestamp()
ts = datetime.datetime.now().timestamp()
total_materials.to_csv(f"saved_materials_{str(ts).split('.')[1]}.csv")
print("材料表已保存到csv文件")
equipment_data = pd.read_csv('material_output_update.csv')
# 创建主窗口
window = tk.Tk()
window.title("装备材料计算器")
# 创建下拉选择框和标签
label_equipment = ttk.Label(window, text="装备名称:")
label_equipment.pack()
combo_equipment = ttk.Combobox(window, values=equipment_data['名称'].unique().tolist())
combo_equipment.pack()
label_level = ttk.Label(window, text="装备等级:")
label_level.pack()
combo_level = ttk.Combobox(window, values=equipment_data['升级等级'].unique().tolist())
combo_level.pack()
# 创建添加按钮
add_button = ttk.Button(window, text="添加", command=add_equipment)
add_button.pack()
# 创建选择列表框
selected_listbox = tk.Listbox(window)
selected_listbox.pack()
# 创建清空选项的按钮
clear_button = tk.Button(window, text='清空选项', command=clear_selected_listbox)
clear_button.pack()
# 创建计算按钮
calculate_button = ttk.Button(window, text="计算", command=calculate_materials)
calculate_button.pack()
# 创建结果文本框
result_text = tk.Text(window, height=10, width=30)
result_text.pack()
# 创建保存按钮
save_button = tk.Button(window, text="保存到csv", command=save_instructions)
save_button.pack()
# 启动主循环
window.mainloop()