HardwareEng.
HardwareEng.

Reputation: 99

Tcl/Tk listbox configuring background for all items

I have a listbox with many many items (lines). Each item may have it's own background color, configure by $my_listbox itemconfigure my_index -background some_color. Is there any option to reset all items' background at once rather than iterating all items? Currently, it is very time consuming task...

I'm running on Windows7 Tk 8.5.14

Upvotes: 0

Views: 285

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137787

It shouldn't be taking that long to change the backgrounds of items in the listbox, not unless you have either far too many items in the listbox (it doesn't scale infinitely, like most GUI elements) or you are running the event loop (perhaps by doing an update or update idletasks) between each call to set an item's background. This is because Tk usually postpones redrawing the widget until it is no longer busy running your callbacks, making the redraw appear to happen at once. All the reconfigure of the item really does is set a record in memory and schedule the later redraw (if there wasn't one already in the pipeline) and that's really quite quick; it was designed to be fast on machines a lot slower than any current desktop or mobile system.

The listbox mostly doesn't support group operations (except for insertion, deletion and retrieval, but those are special cases).

If the fundamental problem is that you're putting too many items in, you'll have to switch to a different widget. For example, the text widget scales better provided you don't use very long lines (or turn off word-wrapping). It also supports a more sophisticated model for how things should be reconfigured via its system of named tags.

Upvotes: 1

Related Questions