From e37da6049549b272fcc0725678e3b3406152961c Mon Sep 17 00:00:00 2001 From: wsh5485 Date: Tue, 14 Jan 2025 01:16:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wsh5485 --- 源码-XJBS_条码处理.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 源码-XJBS_条码处理.py diff --git a/源码-XJBS_条码处理.py b/源码-XJBS_条码处理.py new file mode 100644 index 0000000..84a2537 --- /dev/null +++ b/源码-XJBS_条码处理.py @@ -0,0 +1,58 @@ +import os +from tkinter import Tk, Button, Label, filedialog, messagebox + +class BarcodeProcessor: + def __init__(self, root): + self.root = root + self.root.title("条码处理程序 V0.1.1.20250109 @BLTC") + self.root.geometry("400x150") + + # 创建界面元素 + self.label = Label(root, text="选择要处理的txt文件") + self.label.pack(pady=10) + + self.select_button = Button(root, text="选择文件", command=self.select_files) + self.select_button.pack(pady=5) + + self.process_button = Button(root, text="开始处理", command=self.process_files, state="disabled") + self.process_button.pack(pady=5) + + self.files = [] + + def select_files(self): + self.files = filedialog.askopenfilenames( + title="选择要处理的txt文件", + filetypes=[("Text files", "*.txt")], + initialdir=os.getcwd() + ) + if self.files: + self.process_button.config(state="normal") + self.label.config(text=f"已选择 {len(self.files)} 个文件") + + def process_files(self): + for file in self.files: + try: + with open(file, 'r') as f: + lines = f.readlines() + + modified_lines = [] + for line in lines: + stripped_line = line.strip() + if not stripped_line.endswith(",1"): + modified_lines.append(stripped_line + ",1") + else: + modified_lines.append(stripped_line) + + with open(file, 'w') as f: + f.write('\n'.join(modified_lines)) + except Exception as e: + messagebox.showerror("错误", f"处理文件 {file} 时出错:\n{str(e)}") + return + + messagebox.showinfo("完成", "文件处理完成!") + self.root.destroy() + +if __name__ == "__main__": + root = Tk() + app = BarcodeProcessor(root) + root.mainloop()