From 5bded32fa8cb30f83a38af73cd6b4ce74fc5cd8f Mon Sep 17 00:00:00 2001 From: wsh5485 Date: Tue, 14 Jan 2025 01:16:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20barcode=5Fplus=5Fdot=5F1.p?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... -XJBS_æ¡ç å¤„ç†.py => barcode_plus_dot_1.py | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) rename æºç -XJBS_æ¡ç å¤„ç†.py => barcode_plus_dot_1.py (97%) diff --git a/æºç -XJBS_æ¡ç å¤„ç†.py b/barcode_plus_dot_1.py similarity index 97% rename from æºç -XJBS_æ¡ç å¤„ç†.py rename to barcode_plus_dot_1.py index 84a2537..dd9c8c5 100644 --- a/æºç -XJBS_æ¡ç å¤„ç†.py +++ b/barcode_plus_dot_1.py @@ -1,58 +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() +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()