Python Forum
[Tkinter] Syntax Highlighting in Text Editor
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Syntax Highlighting in Text Editor
#1
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?
Reply
#2
use VSCode, it's automtic with extension.
see: VS Code from start
Reply
#3
(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?
Reply
#4
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
Reply
#5
Maybe you can fix the IDLE console so you don't have to move the cursor to the last line to type.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Indentation for Tkinter-made Text Editor ShakeyPakey 4 5,053 Jun-08-2020, 03:13 PM
Last Post: menator01
  UTF8 for Urdu text editor technifire 2 3,581 Jul-24-2017, 11:15 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020