Search code examples
pythonpython-3.xtkinterttktkinter-text

Is it possible to style a tkinter Text widget?


I've been using the 'ttkthemes' module to add some additional user-selectable themes to my application via an OptionMenu, and all my Text widgets stand out a bit in their standard style.

I would like to know if it is at all possible to style a Tkinter Text widget with ttk themes.
I know you can't actually style the standard Tkinter widget (you instead must use the respective ttk version).
My issue is that there is no ttk.Text only the entry and I need multiple lines for a text editor.

One possibility would be to change background colour based on the selected theme, but this could be very long since there many themes to choose from.

Would anyone know of any possible way to get a stylable version of the Tkinter Text widget, so that it doesn't stand out as much?


Solution

  • Would anyone know of any possible way to get a stylable version of the Tkinter Text widget, so that it doesn't stand out as much?

    You can create your own custom Text widget that listens to the <<ThemeChanged>> event, and then reconfigures itself based on the settings from the current theme or other widgets. For example, you could query the current theme to get the background color of an Entry widget and use that to set the background of the Text widget.