#coding utf-8
import re
import os
patter=re.compile(r"\d+")
from tkinter import *
from tkinter import filedialog
import threading
def openfile():
file = filedialog.askopenfilename(title="打开文件", filetypes=[('All Files',"*.*")])
filespath.set(file)
def activity():
file_path = filespath.get()
with open(file_path) as fp:
data=fp.readlines()
i=0
while(i<len(data)):
#print(type(data))
print(i)
#print(data[i])
if data[i]=="*DEFINE_CURVE_TITLE\n":#记得加回车#print(line)
print(data[i+2])
list=data[i+2].split(" ")
#print(list)
for j in range(len(list)):
result=patter.match(list[j])
if result:
#print(result.group())
data.insert(i,"*CHANGE_CURVE_DEFINITION\n")
data.insert(i+1,result.group()+"\n")
i = i + 3
break;
else:
i=i+1
save_path=file_path+"_changed"
with open(save_path,"w") as sw:
for line in data:
#print(line)
sw.write(line)
sw.close()
if __name__ == "__main__":
root = Tk()
root.title("k_manager")
root.geometry('512x105')
root.resizable(width=False, height=False)
filespathL1 = Label(root, text="kfile_path:", font=11)
filespathL1.grid(row=0, column=0, sticky=E)
filespath = StringVar()
filespath.set("")
filespathE1 = Entry(root, textvariable=filespath, font=11)
filespathE1.grid(row=0, column=1, sticky=E)
'''
filespathL2 = Label(root, text="TXT_path:", font=11)
filespathL2.grid(row=1, column=0, sticky=E)
filespath_text2 = StringVar()
filespath_text2.set("")
filespathE2 = Entry(root, textvariable=filespath_text2, font=11)
filespathE2.grid(row=1, column=1, sticky=E)
'''
Button(root, bd=5, text="open", font=11, command=openfile).grid(row=0, column=3, sticky=E)
#Button(root, bd=1, text="open", font=11, command=openfile_stl).grid(row=0, column=3, sticky=E)
Button(root, bd=5, text="Start_written", font=11, command=activity).grid(row=2, column=1, sticky=E)
#Button(root, bd=5, text="run piper", font=11, command=mutiprocess).grid(row=2, column=1, sticky=E)
# Button(root, bd=5, text="render", font=11, command=on_click).grid(row=2, column=5, sticky=E)
root.mainloop()
有图形界面的k文件修改器
最新推荐文章于 2023-06-09 15:11:27 发布