Search code examples
pythontkintertextboxlistboxcustomtkinter

Python Tkinter listbox color individual word


From this answer I know how to color individual items in a listbox. However, is it possible to color individual words/characters inside the item of a Tkinter listbox?

If yes, how to achieve that?

If no, is there a way to work around the limitations, such as transforming a Tkinter TextBox into a ListBox (so you can click on individual lines), while still being able to color anything and everything?


Solution

  • You cannot change individual words in a Listbox widget. Your only choices are to use a Text widget or a Canvas widget, with the Text widget by far being the easiest.

    You can certainly use the Text widget as the basis for replicating the features of the Listbox. You'll have to add your own bindings for selecting whole lines, and add your own methods and virtual events to emulate the Listbox.