Home > Back-end >  How to change the Text Cursor color in TTKBOOTSTRAP in Python for an Entry widget?
How to change the Text Cursor color in TTKBOOTSTRAP in Python for an Entry widget?

Time:01-04

I am trying to change the color of the text cursor in python using ttkbootstrap.

My end goal is to create an Entry widget whose background is white - this I succeeded; however, the text cursor is "white-ish" and thus I cannot see it.

This is what I have

import ttkbootstrap as tb
import a_module_I_created as tkb

class Window_main:

   def __init__(self, root):

        ''' a bunch of code, this is unimportant'''

        self.table_t1_frame = tb.Frame(self.tab1)
        self.table_t1_frame.grid(row=0, column=6, rowspan=10, padx=25)
        self.table = tkb.Table_tab1(self.table_t1_frame)

root = tb.Window(themename='superhero')
app = Window_main(root)


app.root.mainloop()

On my table, the one that I defined as Table_tab1 I have this:

table_entry_style = tb.Style("litera")
table_entry_style.configure('litera.TEntry', fieldbackground= 'white', foreground='black', insertbackground="black")

        ''' a bunch of code unimportant'''

self.entry[counter] = tb.Entry(frame, style="litera.TEntry", width=10)
self.entry[counter].grid(row=rows, column= col)

Here is a screenshot of the table

enter image description here

It "works" as in, it changes the background of the Entry widget to white and the text to black. However, the text cursor is "white" so I cannot see which Entry box am I going to type into until I actually type.

As you can see I already tried insertbackground and it was suggested below

How to change text cursor color in Tkinter?

How can I change the color of the text cursor to something "dark" so I can see it?

I have tried many methods, such as changing the "style" to litera (only the widget's style since I want to keep the theme "superhero" for the rest of the app) but it did not work.

I tried using other styles colors like "success", "light", "primary" etc. inside configure using configure(theme_use="success") etc. but it did not work.

My guess is that the main theme "superhero" is overwriting everything.

Can somebody help me?

This is the link to the ttkbootstrap documentation https://ttkbootstrap.readthedocs.io/en/latest/themes/light/

CodePudding user response:

The ttk styling option for the cursor is insertcolor.

I don't have ttkbootstrap installed, but I'm guessing this should work:

table_entry_style.configure('litera.TEntry', ..., insertcolor="black")
#                                                 ^^^^^^^^^^^^^^^^^^^
  • Related