I'm using tkinter and I am trying to compare a string [in this case, the original file] to text in a text widget. Here's the function and where I call the function:
def checkText():
if(text.get("1.0", "end-1c") != currentText):
print("Changed")
root.after(1000, checkText())
and where I call:
root.after(1000, checkText()) #after 1 second, check text to see if it has changed
It returns the error:
File "main.py", line 65, in checkText
if(text.get("1.0", "end-1c") != currentText):
RuntimeError: maximum recursion depth exceeded
Except with hundreds of 'File "main.py", line 65, in checkText'
Probably something obvious I'm overlooking, but help is appreciated.
Those are the only places the function is used or referenced to in the program, but just incase, here is where currentText is defined:
myfile = tkFileDialog.askopenfile(title='Open a file', mode='r')
text.delete('1.0', END)
loadedfile = myfile.read()
currentText = myfile.read()
loadedFile is put directly into the text widget and works fine, so I assume currentText should be the same as loadedFile/text in the widget.
Thanks.
edit: formatting, also I realized I can just say currentText = loadedFile
to simplify it, but I am keeping the original code in the question
edit: Entire function for getting text
def fileOpen(textView):
try:
myfile = tkFileDialog.askopenfile(title='Open a file', mode='r')
text.delete('1.0', END)
loadedfile = myfile.read()
currentText = loadedFile
currentFile = myfile.name
currentName = currentFile
currentName = currentName.rsplit('/', 1)[-1] #get the 'name.ext' part only
currentName = currentName.rsplit('\\', 1)[-1] #incase you're using windows
currentFileButton.config(text = currentName)
myfile.close()
textView.insert("end", loadedfile)
except:
return
def saveAs(): #define how to save files
try:
global text
t = text.get("1.0", "end-1c")
saveLocation = tkFileDialog.asksaveasfilename()
file1 = open(saveLocation, "w+")
file1.write(t)
file1.close()
except:
return
later:
text = Text(textFrame, bd=0, bg=color, fg=textColor) #make text editor box