Python Forum
[Tkinter] Syntax Highlighting in Text Editor - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: [Tkinter] Syntax Highlighting in Text Editor (/thread-27526.html)



Syntax Highlighting in Text Editor - ShakeyPakey - Jun-09-2020

I am wondering if there is a way using the Python module tkinter to colour text, or do "syntax highlighting". I am making my own text editor using tkinter, and I want to check if the user types one of numerous keywords. If they do type a keyword, then the word is highlighted.

class TextEditor:

    def __init__(self, master):
        master.title("Untitled - TextEditor")
        master.geometry("1200x700")

        self.textarea = tk.Text(master,font=("ubuntu",12))
The code above contains the definition of the text area, which uses the tk.Text widget.

Is there any way I can check the text being written by the user in real-time, and when they type a keyword, then that word is highlighted?
If you are answering this, can you give me an example of the word "print" being highlighted in red?


RE: Syntax Highlighting in Text Editor - Larz60+ - Jun-09-2020

use VSCode, it's automtic with extension.
see: VS Code from start


RE: Syntax Highlighting in Text Editor - ShakeyPakey - Jun-09-2020

(Jun-09-2020, 06:45 PM)Larz60+ Wrote: use VSCode, it's automtic with extension.
see: VS Code from start

I think you have misunderstood my question?


RE: Syntax Highlighting in Text Editor - Yoriz - Jun-09-2020

Open idle, type print, it will be highlighted in red, idle is written with tkinter.
You can view the files that went into making idle in your python folder \Lib\idlelib

https://stackoverflow.com/questions/3781670/how-to-highlight-text-in-a-tkinter-text-widget
https://stackoverflow.com/questions/38594978/tkinter-syntax-highlighting-for-text-widget
https://github.com/JamesStallings/pyro


RE: Syntax Highlighting in Text Editor - deanhystad - Jun-10-2020

Maybe you can fix the IDLE console so you don't have to move the cursor to the last line to type.