DearPyGui icon indicating copy to clipboard operation
DearPyGui copied to clipboard

Add a method to update item's color

Open vsukhoml opened this issue 9 months ago • 5 comments

add_text() allows to set color of the text, set_value() can update text, but there is no way to update a color of the text.

For add_selectable() it is possible to update displayed text with set_item_label(), but there is no clear way to set the color of the displayed text.

Context: I'm trying to implement a dynamically updated table with selectable rows where color of values may change with each update and so far the only solution I found is to remove all rows and add them again with desired attributes.

vsukhoml avatar Apr 05 '25 18:04 vsukhoml

I'd suggest that you start with the doc on themes (this will help with the selectable) and on item configuration (this one is for color on add_text).

Also please note that the selectable only paints its background in selected or hovered state. There's no way to fill its background in normal unselected non-hovered state (because it simply doesn't paint background in this state). Text color, on the other hand, should be easy to set up. Try adding dpg.show_style_editor() before start_dearpygui in your program to see what other colors are available.

Also note that tables support highlight_table_row, or alternatively you can bind a theme directly to the row in order to change its background color (and note that there are two background colors for rows - that's to implement striped tables).

v-ein avatar Apr 05 '25 21:04 v-ein

Thanks for the idea with themes! So this would be the recommended approach here - define a collection of themes to apply to items as needed? I was thinking that just changing a color attribute can be a lighter approach.

vsukhoml avatar Apr 05 '25 22:04 vsukhoml

It really depends on your needs and what you're going to do with that piece of UI in future. Setting the color on add_text is definitely a more lightweight approach - at the cost of flexibility though. Well, you can always start with just the color attribute, and change to themes if need be.

v-ein avatar Apr 06 '25 06:04 v-ein

Please don't click the link in the notification you received for the previous comment. It's a scam.

v-ein avatar Apr 16 '25 18:04 v-ein