Python Forum

Full Version: Syntax Highlighting in Text Editor
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
use VSCode, it's automtic with extension.
see: VS Code from start
(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?
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/3781...ext-widget
https://stackoverflow.com/questions/3859...ext-widget
https://github.com/JamesStallings/pyro
Maybe you can fix the IDLE console so you don't have to move the cursor to the last line to type.