[Python] 纯文本查看 复制代码
import tkinter as tk
import re
# -*- encoding: utf8 -*-
import tkinter as tk
from tkinter import ttk
from tkinter import Toplevel
import tkinter.filedialog
from tkinter import messagebox
import tkinter.simpledialog
import os
from tkinter import *
from hashlib import md5
import re
import textwrap
import tkinter.font as tkFont
import random
# root = tk.Tk()
# root.title('正则')
#
# var = tk.StringVar()
# var.set("还没开始转换...")
#
#
#
# def fun():
# txt1 = text1.get('0.0', 'end')
# txt2 = text2.get('0.0', 'end')
# print(txt1, txt2)
# text3s = re.findall(text2, text1)
# for x in text3s:
# print(x)
# # 将结果赋给var变量
# var.get(x)
# text3.insert(tk.END, var)
#
#
# # text1用来接收待处理文本
# text1 = tk.Text(root, height=10, width=30)
# text1.grid(row=1, column=0)
#
# label = tk.Label(root, text="请输入正则文本:")
# label.grid(row=0, column=0)
#
# # text2用来接收正则表达式
# text2 = tk.Text(root, height=1, width=20, bg='yellow', fg='blue')
# text2.grid(row=0, column=1)
#
# button = tk.Button(height=5, width=10, text="开始转换", command=fun)
# button.grid(row=1, column=1)
#
# # text3用来显示匹配后的结果
# text3 = tk.Text(root, height=10, width=30)
# text3.insert(tk.END, var)
# text3.grid(row=2, column=0)
#
# root.mainloop()
class Editor:
def __init__(self, master):
self.master = master
self.master.title("正则")
self.frame = tk.Frame(self.master)
#
self.frame.grid()
text1 = tk.Text(self.frame, height=10, width=30)
text1.grid(row=1, column=0)
#
label = tk.Label(self.frame, text="请输入正则文本:")
label.grid(row=0, column=0)
#
# # text2用来接收正则表达式
text2 = tk.Text(self.frame, height=1, width=20, bg='yellow', fg='blue')
text2.grid(row=0, column=1)
#
button = tk.Button(height=5, width=10, text="开始转换", command=lambda: self.fun([text1.get(1.0, 'end'), text2.get(1.0, 'end')]))
button.grid(row=1, column=1)
# text3用来显示匹配后的结果
global text3
text3 = tk.Text(self.frame, height=10, width=30)
# text3.insert(tk.END, var)
text3.grid(row=2, column=0)
def fun(self, value):
txt1 = str(value[0]).strip()
txt2 = str(value[1]).strip()
print(txt1)
print(txt2)
text3s = re.findall(txt2, txt1)
for x in text3s:
print(type(x))
print(x)
text3.delete(1.0,'end')
text3.insert('1.0', x)
def main():
root = tk.Tk()
app = Editor(root)
# 设置窗口大小
winWidth = 600
winHeight = 600
# 获取屏幕分辨率
screenWidth = root.winfo_screenwidth()
screenHeight = root.winfo_screenheight()
x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)
# 设置窗口初始位置在屏幕居中
root.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
#root.geometry("600x600+10+15")
# 设置窗口图标
#root.iconbitmap("./icons/Create.ico")
root.mainloop()
if __name__ == '__main__':
main()