Home > database >  Displaying statements with colours and symbols using tkinter text widget
Displaying statements with colours and symbols using tkinter text widget

Time:06-03

I have created a GUI app using tkinter that prints messages to the user via the text widget. The app checks if the paper size of a document is A4 or not (via a series of loops and functions) and then prints appropriate messages.

The code was written using Python (3.10) on PyCharm (Community Edition 2021.3.3). The modules used are: tkinter (8.6) and python-docx (0.8.11).

I tried to print a message that starts with a check mark written in green text colour when the paper size is A4. But the message did not print properly. The code used to print this is shown below.

I suspect that the text widget may not be recognise the symbol and colour codes used. I would like to know how I can insert such statements in the text widget. Or if perhaps there is another tkinter widget that allows such implementations.

I have tried the solutions presented in this post: Changing the colour of text automatically inserted into tkinter widget But this was not suitable for my purpose.

output_display.insert(1.0, '\033[92m'   '\u2705', "All pages are A4."   '\033[0m')

CodePudding user response:

Those escape codes are only recognized by your terminal. You can use "tags" to color portions of a text widget.

https://www.geeksforgeeks.org/change-the-color-of-certain-words-in-the-tkinter-text-widget/

  • Related