最后一个不正经tkinter的工具
# -*- coding: utf-8 -*- from tkinter import * import pyperclip import re window = Tk() # 标题 window.title('qcc_cut_row0.1') window.geometry('500x800+100+50') # 设置标签行 l = Label(window, text='敏捷每行', bg='green', fg='white', font=('Arial', 12), width=30, height=2) l.pack() # 敏捷分行过滤条件 E2 = Text(window, width='200', height='1', background='LightYellow1', font='1') E2.pack() # background E1 = Text(window, width='200', height='50') # 分离中文 with open('测试.txt', encoding='utf-8') as strs: res = strs.read() print(res) # 分离中文 def cut_ch(): # 清空程序中以整理的文本 E1.delete('1.0', 'end') strs = res.split('\n') for str in strs: # 正则表达式的判断是否含有英文不包含就算中文 print('asdsadas',''.join(re.findall(r'[A-Za-z]', str))) if len(''.join(re.findall(r'[A-Za-z]', str))) > 1: if len(str) > 1: print(str.strip('\n')) # 填写程序中以整理的文本 E1.insert("insert", str+'\n') # 文本框定位 E1.place(x='0',y='100') # 抽取文本框内容至剪切板 pyperclip.copy(E1.get('1.0', 'end')) # 分离英文 def cut_en(): E1.delete('1.0', 'end') with open('测试.txt', encoding='utf-8') as strs: for str in strs: str = str.strip('\n') # 正则表达式的判断是否含有英文包含就算英文 if len(''.join(re.findall(r'[A-Za-z]', str))) < 1: if len(str) > 0: print(str.strip('\n')) E1.insert("insert", str + '\n') E1.place(x='0',y='100') pyperclip.copy(E1.get('1.0', 'end')) # 遇到空格分行 def balck_cut(): E1.delete('1.0', 'end') with open('测试.txt', encoding='utf-8') as strs: for str in strs: # 遇到空格分行 小伙子 循环输出 s = str.split(' ') for i in s: E1.insert("insert", i.strip('\n') + '\n') E1.place(x='0',y='100') pyperclip.copy(E1.get('1.0', 'end')) # 自定义分行 def all_cut_new(): E1.delete('1.0', 'end') with open('测试.txt', encoding='utf-8') as strs: for strr in strs: # 获取E2中的数据进行分行 实际是转换为列表 循环输出 hh =E2.get('1.0', 'end').replace('\n','') s = strr.strip('\n').split(hh) for i in s: E1.insert("insert", i.strip('\n')+'\n') E1.place(x='0',y='100') pyperclip.copy(E1.get('1.0', 'end')) # 自定义分行过滤 def clean_row(): E1.delete('1.0', 'end') hh =E2.get('1.0', 'end').replace('\n','') with open('测试.txt', encoding='utf-8') as strs: for strr in strs: # 判断每行的开头是否为E2中的内容 是则过滤 不是则填写至 E1中 if strr[0]!=E2.get('1.0', 'end').replace('\n',''): E1.insert("insert", strr) E1.place(x='0',y='100') pyperclip.copy(E1.get('1.0', 'end')) # 按钮布局 img_txt1 = Button(window, text='分离中文', font=('Arial', 10), width=10, height=1, command=cut_ch) img_txt2 = Button(window, text='分离英文', font=('Arial', 10), width=10, height=1, command=cut_en) img_txt3 = Button(window, text='空格分行', font=('Arial', 10), width=10, height=1, command=balck_cut) img_txt4 = Button(window, text='敏捷分行', font=('Arial', 10), width=10, height=1, command=all_cut_new) img_txt5 = Button(window, text='过滤分行', font=('Arial', 10), width=10, height=1, command=clean_row) img_txt1.place(x='0',y='70') img_txt2.place(x='90',y='70') img_txt3.place(x='180',y='70') img_txt4.place(x='270',y='70') img_txt5.place(x='360',y='70') window.attributes('-topmost',1) # 窗口循环 window.mainloop()
Auto Copied
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人