SmileyJames
SmileyJames

Reputation: 117

How do I change the text colour of an active cell in a TkTable in Python?

I am using a tktable in an application I am making using the Python's tkinter module.

When I select a cell and type in it the colour of the text is white, which is very hard to read. How do I change this colour to black for example.

I have already changed the 'foreground' colour, yet I has not made a difference.

self.table = tktable.Table(self, rows=5, cols=5, multiline=0, font=("Helvetica", 10), foreground='Red', background='White', cache=True, colstretchmode='all')

self.table.grid(row=0, column=1, padx=10, pady=10, sticky='e,w')

FULL SOLUTION FOR PEOPLE WHO FIND THIS THREAD:

import Tkinter as tk
import tktable

class App(tk.Frame):
    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.parent = parent
        self.Main()
        self.grid()

    def Main(self):
        self.table = tktable.Table(self, rows=5, cols=5, multiline=0, font=("Helvetica", 10), foreground='Black', background='White', cache=True, colstretchmode='all')
        self.table.tag_configure('active', foreground='black') # <<<ADDED LINE/ SOLUTION
        self.table.grid(row=0, column=0, padx=10, pady=10, sticky='e,w')

if __name__ == "__main__":
    root = tk.Tk()
    app = App(root)
    app.mainloop()

Upvotes: 4

Views: 1364

Answers (1)

Oblivion
Oblivion

Reputation: 1729

When a cell is selected for editing, the 'active' tag comes into effect.

try something like:

self.table.tag_configure('active', foreground='black')

Upvotes: 5

Related Questions