Akascape / CTkTable

Customtkinter Table widget (extension/add-on)
MIT License
265 stars 15 forks source link

Add text color extranction function #111

Closed wpdbs1229 closed 1 hour ago

wpdbs1229 commented 21 hours ago

Hi, Akascape

I was using CTkTable and created a function to extract text color. I thought it might be the same function for other people to use, so I left an issue like this. The code below is a function to extract text color, it does not extract the text color of the header.

def get_column_text_color(self, column_index):
        text_colors = []
        for row in range(1, self.rows):
            text_color = self.data.get((row, column_index), {}).get("args").get("text_color")
            text_colors.append(text_color)
        return text_colors

This is example code

import customtkinter
from CTkTable import *
from CTkColorPicker import *

root = customtkinter.CTk()

def show(cell):

    if cell["column"] == 4:
        table.select(cell["row"], cell["column"])
        pick_color = AskColor() # open the color picker
        color = pick_color.get() # get the color string
        table.insert(cell["row"], cell["column"], value=table.get(cell["row"], cell["column"]), text_color = color)

def get_text_color():
   color_column_list = table.get_column_text_color(4)
   for color_column in color_column_list:
       print(color_column)

value = [["A","B","C","D","E"],[1,2,3,4,"▇▇"],[0,0,0,0,"▇▇"],[1,2,0,0,"▇▇"],[1,2,3,4,"▇▇"]]

table = CTkTable(master=root, row=5, column=5, values=value, command=show ,header_color="green")
table.pack(expand=True, fill="both", padx=20, pady=20)

btn = customtkinter.CTkButton(root, text='color print', width=150, command=get_text_color)
btn.pack(expand=True,pady=5, padx=5)
root.mainloop()

I extracted the text code and used it to color the graph. If it's okay, may I request a PR? example

Akascape commented 11 hours ago

@wpdbs1229 Better convert this into a discussion.

wpdbs1229 commented 1 hour ago

@wpdbs1229 Better convert this into a discussion.

Ok, Thanks for replying