I am using pytesseract with tkinter. My current code is as follows
def imagetostring():
filepath = filedialog.ask.openfilename(title = "Select File", filetypes = (("PNG", "*.png")))
output = pytesseract.image_to_string(Image.open(filepath))
fp = filepath[:-4]
filepathn = fp + ".txt"
subprocess.run("echo.>" + filepathn + " && " + "echo " + output + "> " + filepathn,shell=True)
print(output)
What I am trying to do is use pytesseract to convert the image text to string and create a file of the same name with the .txt extension with the image text inside the file. However the txt file comes up empty. If I put a string inside of the output variable in the same process or if the variable contains a written out string it is successful however it doesn't work with the pytesseract.image_to_string. Yet when I print the output variable it does appear in the vscode output terminal.