commit e37da6049549b272fcc0725678e3b3406152961c Author: wsh5485 Date: Tue Jan 14 01:16:01 2025 +0800 上传文件至 / Signed-off-by: wsh5485 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()