Path: ...!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: greg Newsgroups: comp.lang.tcl Subject: Re: A ttk:combox with colors? Date: Sun, 3 Nov 2024 08:55:51 +0100 Organization: A noiseless patient Spider Lines: 70 Message-ID: References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 03 Nov 2024 08:55:51 +0100 (CET) Injection-Info: dont-email.me; posting-host="be265aa596638e3d436c4b009952cf8d"; logging-data="301757"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4dTYk2yOIX4/yEej7k7JSHaNSJSglvsc=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:OS+BvLvD+OHkE+PUxPXc+wnmRkk= Content-Language: de-DE In-Reply-To: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com> Bytes: 3136 Am 02.11.24 um 22:24 schrieb Helmut Giese: > Hello out there, > I would like to have a combobox display stripes of colors instead of > text and the selection coloring the background of the combo's text > field. How could I go about creating such a beast (or maybe it exists > already)? > Any link or idea will be highly appreciated > Helmut Hello Helmut, I use the internal listbox of combobox. When I select an element for the first time, the text in the combobox is visible for a short time. I have no idea. Gregor #! /usr/bin/env tclsh package require Tk # Procedure to style the listbox items # interna popdown.f.l # https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm proc styleListbox {cb} { set popdown [ttk::combobox::PopdownWindow $cb] set lb "$popdown.f.l" set colors [$cb cget -values] set i 0 foreach color $colors { $lb itemconfigure $i -background $color $lb itemconfigure $i -foreground $color $lb itemconfigure $i -selectbackground $color $lb itemconfigure $i -selectforeground $color incr i } } # Create a combobox with the custom style set selectedValue "" ttk::combobox .cb -style CustomCombobox.TCombobox \ -values [list "green" "red" "white" "yellow" "black"] \ -textvariable selectedValue -state readonly pack .cb -padx 20 -pady 20 # Event binding to style the internal listbox when the combobox is opened bind .cb { after 100 {styleListbox .cb} } # Event binding # https://wiki.tcl-lang.org/page/ttk%3A%3Acombobox # Disabled/Readonly color (and pointer to color change) bind .cb <> { ttk::style map CustomCombobox.TCombobox -fieldbackground "readonly $selectedValue" ttk::style map CustomCombobox.TCombobox -foreground "readonly $selectedValue" ttk::style map CustomCombobox.TCombobox -background "readonly $selectedValue" ttk::style map CustomCombobox.TCombobox -selectforeground "readonly $selectedValue" ttk::style map CustomCombobox.TCombobox -selectbackground "readonly $selectedValue" } ..cb set "white" event generate .cb <>