| Deutsch English Français Italiano |
|
<vg92mc$jcas$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: greg <gregor.ebbing@gmx.de>
Newsgroups: comp.lang.tcl
Subject: Re: A ttk:combox with colors?
Date: Mon, 4 Nov 2024 00:58:04 +0100
Organization: A noiseless patient Spider
Lines: 91
Message-ID: <vg92mc$jcas$1@dont-email.me>
References: <3o5dij1b6quvgruokjidhqtii5bd8csn7q@4ax.com>
<vg7aa7$96lt$2@dont-email.me> <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 04 Nov 2024 00:58:05 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d1622d9f29ffae309d86a18f7773b4f6";
logging-data="635228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/scrEvvEtGZ1QOWFxOjMT0448MxQMxqXk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FmPDDCIzFfxQgK6gZiNiTQrSSDc=
In-Reply-To: <seufijtvecnore0l6f7hfgtioc8al7407s@4ax.com>
Content-Language: de-DE
Bytes: 4087
Am 03.11.24 um 23:46 schrieb Helmut Giese:
> Hello greg,
> thanks a lot for the code. Impressive: knowing about the internal
> 'popdown.f.l' and handling ttk::style - something I have (as yet?) not
> understood.
> Alas, for me it works only half: The color gets selected as wanted,
> but only covers a small part of the entry field, the rest being either
> blue when the combo has the focus and white when not. I made screen
> shots and uploaded them to 'file.io' under the URL
> https://file.io/SWF4GKTWvUva
> in case you want to have a look.
> Interesting: The width of the colored part seems to vary for all
> colors - most notably for 'red' and 'yellow'.
> Nevertheless thank you for the code
> Helmut
> PS: I am on Windows 10 and run Tcl8.6.14 or ...12
Hello Helmut
The solution has the following limitation: it does not work with a naive
theme.
(Can only be changed when using non-native and non-graphical theme) from
Manual
The ttk::combobox consists of a ttk::entry and a tk::listbox
It's in the manual
https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
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
#text color in listbox
#$lb itemconfigure $i -selectforeground $color
incr i
}
}
# https://www.tcl.tk/man/tcl8.6/TkCmd/ttk_combobox.htm
# Can only be changed when using non-native and non-graphical themes
ttk::style theme use clam
set selectedValue ""
# Create a combobox with the custom style
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 5 [list styleListbox %W]
}
# Event binding
# https://wiki.tcl-lang.org/page/ttk%3A%3Acombobox
# SHOW Disabled/Readonly color (and pointer to color change)
# https://wiki.tcl-lang.org/page/Changing+Widget+Colors
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>>