Author: Csaba Nemethi <csaba.nemethi@t-online.de>
State: Final
Type: Project
Tcl-Version: 9.1
Vote: Done
Created: 27-Jan-2026
Keywords: listbox, widget, Tk
Tk-Branch: listbox_select_colors
Vote-Summary: Accepted 6/0/0
Votes-For: HO, KW, BG, MC, APN, SL
Votes-Against: none
Votes-Present: none
Abstract
This TIP proposes to add the -inactiveselectbackground and
-inactiveselectforeground options to the listbox widget and
use them to make the selection colors native-conform also when the widget does
not have the input focus.
Rationale
In the themes aqua, vista, and
winnative, the selection in a ttk::treeview widget appears as
white text on a theme-specific darker background. In the case of the
aqua theme this is the result of a recent change, described in
the patch Use the native selection colors for listbox and ttk::treeview
widgets on aqua. (Earlier Tk
versions on the Mac used the same selection colors in ttk::treeview widgets as
in themed entries, comboboxes, and spinboxes, rather than the selection colors
of native list and table views.)
The graphics engines on macOS and Windows change the selection colors of the
native list and table views when the window loses the input focus, resulting,
e.g., in black text on a light gray background. The enhanced treeview
implementation (WIP by
Brian O'Hagan) does the same with ttk::treeview widgets in the themes
aqua, vista, and winnative,
due to the adoptation of the changes for the aqua theme
proposed in the patch mentioned above, as well as to a few simple additions to
the files library/ttk/vistaTheme.tcl and
library/ttk/winTheme.tcl. OTOH, currently the selection colors of
a Tk listbox remain unchanged, regardless of whether the widget has the focus
or not. Since this behavior differs from that of the native list views, this
TIP proposes to make it native-conform with the aid of the new listbox
configuration options -inactiveselectbackground and
-inactiveselectforeground.
Specification
The updated listbox manual in the Tk branch listbox_select_colors contains the following description of the above-mentioned new listbox options:
Command-Line Name:-inactiveselectbackground
Database Name: inactiveSelectBackground
Database Class: Foreground
Specifies the background color to use for the selection when the
window does not have the input focus. The option's value may be
an empty string or have any of the forms accepted by Tk_GetColor.
If empty then the value of the -selectbackground widget or item
configuration option is used when the window does not have the
focus. The default value depends on the windowing system: it is
non-empty on aqua and win32, and an empty string on x11.
Command-Line Name:-inactiveselectforeground
Database Name: inactiveSelectForeground
Database Class: Background
Specifies the foreground color to use for the selection when the
window does not have the input focus. The option's value may be
an empty string or have any of the forms accepted by Tk_GetColor.
This option is only relevant if the value of the -inactiveselect‐
background option is non-empty, in which case, if the value of
this option is an empty string then the value of the -selectfore‐
ground widget configuration option is used when the window does
not have the focus. The default value depends on the windowing
system: it is non-empty on aqua and win32, and an empty string on
x11.
Note that there is also a text widget option called
-inactiveselectbackground, having the database name
inactiveSelectBackground and database class
Foreground, but its handling is slightly different from that
of the listbox option of the same name.
REMARK: It might appear somewhat strange that the database class of the
-inactiveselectbackground option is
Foreground and that of
-inactiveselectforeground is Background, but
this is in accordance with the fact that the standard configuration options
-activebackground, -insertbackground, and
-selectbackground are of the database class
Foreground, and the standard options
-activeforeground and -selectforeground are
of the class Background.
Reference Implementation
A ready-to-use reference implementation can be found in the Tk branch
listbox_select_colors. The two new
options are contained in the updated file generic/tkListbox.c, and
their default values are defined in the files
macosx/tkMacOSXDefault.h, unix/tkUnixDefault.h, and
win/tkWinDefault.h. The man page doc/listbox.n and
the file tests/listbox.test have been extended accordingly.
Copyright
This document has been placed in the public domain.