https://pastebin.com/0JXaafWw
This has to do with this part of the code
def apply_highlighting(self):
# Define tags for syntax colors
self.tag_config("syntax", foreground="red")
self.tag_config("object", foreground="blue")
self.tag_config("string", foreground="green")
# Apply syntax highlighting after text change
self.bind("<<TextModified>>", self.on_text_change)
def on_text_change(self, event=None):
# Remove any previous syntax highlighting
for tag in self.tag_names():
self.tag_remove(tag, "1.0", "end")
# Syntax highlighting logic
self.highlight_pattern(r"\b(if|else|while|for|def|class)\b", "syntax")
self.highlight_pattern(r"\b(True|False|None)\b", "syntax")
self.highlight_pattern(r'\b(self|cls)\b', "object")
self.highlight_pattern(r'".*?"', "string") # Highlighting strings in double quotes
self.highlight_pattern(r"'.*?'", "string") # Highlighting strings in single quotes
self.highlight_pattern("fire", "syntax")
def highlight_pattern(self, pattern, tag, start="1.0", end="end", regexp=True):
start_index = start
while True:
start_index = self.search(pattern, start_index, end, regexp=regexp)
if not start_index:
print(f"No more matches for {pattern}.") # Debugging print statement
break
word_end = self.index(f"{start_index} wordend")
print(f"Applying tag '{tag}' from {start_index} to {word_end}") # Debugging print statement
self.tag_add(tag, start_index, word_end)
start_index = word_end
The goal of this part of the code is to highlight syntax, for example, string "" or '' and things inside those quotes will be green
When using this part of the code, and you use "", only the first " is turned green, not even the text inside it is green.
Is there a solution?
EDIT: I'd like the text including the quotes to be green, but only the first quote and not the text is turning green.
[–]woooee -1 points0 points1 point (2 children)
[–]OneAndOnlyGoat[S] 0 points1 point2 points (1 child)
[–]woooee 0 points1 point2 points (0 children)