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
| import tkinter as tk from tkinter import filedialog import os import json import time
input_spool_dir = os.path.join(os.getcwd(), 'input_spool')
class PrintTask: def __init__(self, task_id, file_path, title, author, description): self.task_id = task_id self.file_path = file_path self.title = title self.author = author self.description = description self.status = "等待"
def submit_artwork(): file_path = filedialog.askopenfilename() if not (title_entry.get() and author_entry.get() and description_entry.get()): status_label.config(text="请填写完整作品标题、作者和描述信息后再提交!") return
task_id = len(os.listdir(input_spool_dir)) if os.path.exists(input_spool_dir) else 0 task = { "task_id": task_id, "file_path": file_path, "title": title_entry.get(), "author": author_entry.get(), "description": description_entry.get(), "timestamp": time.time() }
task_file_path = os.path.join(input_spool_dir, f'task_{task_id}.json') with open(task_file_path, 'w') as f: json.dump(task, f) status_label.config(text=f"作品已提交,任务ID:{task['task_id']}") title_entry.delete(0, tk.END)
root = tk.Tk() root.title("虚拟打印画廊提交界面") root.geometry("200x200") root.attributes('-toolwindow', True)
title_label = tk.Label(root, text="作品标题:").pack() title_entry = tk.Entry(root).pack()
submit_button = tk.Button(root, text="提交作品", command=submit_artwork).pack() status_label = tk.Label(root).pack()
if not os.path.exists(input_spool_dir): os.makedirs(input_spool_dir)
if __name__ == "__main__": root.mainloop()
|