Today in class, I made a spelling checker. When you spell a word wrong it turns the word red.

This is the check code:
def check(self, event):
content = self.text.get("1.0", tk.END)
space_count = content.count(" ")
if space_count != self.old_spaces:
self.old_spaces = space_count
for tag in self.text.tag_names():
self.text.tag_delete(tag)
for word in content.split(" "):
if re.sub(r"[^\w]", "", word.lower()) not in words.words():
position = content.find(word)
self.text.tag_add(word, f"1.{position}", f"1.{position + len(word)}")
self.text.tag_config(word, foreground="red")

No Responses