社区讨论
数据点编辑器(python)
题目总版参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @lz81d9gl
- 此快照首次捕获于
- 2024/07/30 14:27 2 年前
- 此快照最后确认于
- 2024/07/30 14:36 2 年前
数据点编辑器
PYTHONimport tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog as filedialog
import zipfile
def add_test_point():
global test_point_counter
input_value = input_text.get("1.0", tk.END).strip()
output_value = output_text.get("1.0", tk.END).strip()
test_points_text.insert(tk.END, f"输入值:\n{input_value}\n输出值:\n{output_value}\n\n")
input_text.delete("1.0", tk.END)
output_text.delete("1.0", tk.END)
test_point_counter += 1
input_values.append(input_value)
output_values.append(output_value)
def set_save_path():
global save_path
save_path = filedialog.askdirectory()
path_label.config(text=f"当前选择的路径: {save_path}")
def create_zip_file():
if not save_path:
set_save_path()
file_name = file_name_entry.get()
file_path = f"{save_path}/{file_name}.zip"
with zipfile.ZipFile(file_path, 'w') as zipf:
for i in range(test_point_counter):
zipf.writestr(f"{i}.in", input_values[i])
zipf.writestr(f"{i}.out", output_values[i])
root = tk.Tk()
root.title("测试点编辑器2.0")
input_label = ttk.Label(root, text="输入值:")
input_label.pack()
input_text = tk.Text(root, height=5, width=50)
input_text.pack()
output_label = ttk.Label(root, text="输出值:")
output_label.pack()
output_text = tk.Text(root, height=5, width=50)
output_text.pack()
add_button = ttk.Button(root, text="确定", command=add_test_point)
add_button.pack()
test_points_text = tk.Text(root, height=20, width=50)
test_points_text.pack()
file_name_label = ttk.Label(root, text="文件名:")
file_name_label.pack()
file_name_entry = ttk.Entry(root)
file_name_entry.pack()
browse_button = ttk.Button(root, text="浏览", command=set_save_path)
browse_button.pack()
path_label = ttk.Label(root, text="当前选择的路径: ")
path_label.pack()
save_button = ttk.Button(root, text="保存为压缩包", command=create_zip_file)
save_button.pack()
test_point_counter = 0
input_values = []
output_values = []
save_path = ""
root.mainloop()
回复
共 2 条回复,欢迎继续交流。
正在加载回复...