This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
XJBS_barcode_plus_dot_1/barcode_plus_dot_1.py
T
2025-01-14 01:16:29 +08:00

59 lines
2.0 KiB
Python

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()