Re: A ttk:combox with colors?

Liste des GroupesRevenir à cl tcl 
Sujet : Re: A ttk:combox with colors?
De : gregor.ebbing (at) *nospam* gmx.de (greg)
Groupes : comp.lang.tcl
Date : 03. Nov 2024, 08:55:51
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vg7aa7$96lt$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
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 <ButtonPress-1> {
  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 <<ComboboxSelected>> {
  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 <<ComboboxSelected>>

Date Sujet#  Auteur
2 Nov 24 * A ttk:combox with colors?6Helmut Giese
3 Nov 24 +- Re: A ttk:combox with colors?1greg
3 Nov 24 `* Re: A ttk:combox with colors?4greg
3 Nov 24  `* Re: A ttk:combox with colors?3Helmut Giese
4 Nov 24   `* Re: A ttk:combox with colors?2greg
4 Nov 24    `- Re: A ttk:combox with colors?1Helmut Giese

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal