I am currently using this to try to extract text and strings etc in between quotes and load the text box with the extracted text/string. I am wondering if there is a way to write the text back inside of the text document to the exact position that it was originally in or write it back between the quotes I am extracting from now?
For example if I had a line like this in the text document:
Random Text Random Text "Hello world, this is text document file.txt" Random Text Random Text
How could I be able to extract what is inside the quotes and edit it in the text box and then write it back to where it came from?
This code works to do everything but write it back to the text document in between the quotes. I could not figure that part out. It writes to the text document just fine as is but it over-wrights the file in the current config. I have been looking into readlines, writelines and regex etc to solve this but I am stumped.
from Tkinter import *
import re
root = Tk()
with open('file.txt', 'r') as f:
data = ''.join(f.readlines())
m = re.search('"([^"]*)"', data, re.S | re.M)
tBox = Text(root, height=2, width=50)
tBox.insert(END, m.group(1))
tBox.pack()
def retrieve_input():
inputV = tBox.get("1.0", "end-1c")
f = open('file.txt', 'w')
f.write(inputV)
f.close()
btn = Button(root, text="Go", command=lambda: retrieve_input())
btn.pack()
root.mainloop()