首页 > 技术文章 > 最后一个不正经tkinter的工具

t-dashuai 2022-05-03 22:42 原文

# -*- 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

推荐阅读