Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Configure background of ttk::combobox

51 views
Skip to first unread message

Markos

unread,
Apr 15, 2018, 9:56:55 AM4/15/18
to
Hello,

I'm trying to set the background colors of a combobox but I'm not getting it.

set category_list {student ex_student visitor collaborator}

set category_pt student

ttk::combobox .n.f3.category -textvariable category_pt -state readonly \
-values $category_list

.n.f3.category configure -background white

and

ttk::combobox .n.f3.category -textvariable category_pt -state readonly \
-values $category_list -style TCombobox

ttk::style map TCombobox -background {readonly white disabled #d9d9d9}

or
ttk::style configure TCombobox -background white

Any tip?

Thank you,
Markos

Brad Lanam

unread,
Apr 15, 2018, 12:29:39 PM4/15/18
to
What operating system are you using, and what theme?

puts [ttk::style theme use]

Markos

unread,
Apr 16, 2018, 2:56:23 PM4/16/18
to
Hi Brad,

puts [ttk::style theme use]
default
%

I'm using Debian Jessie (8.0) and Tcl/Tk 8.6

Brad Lanam

unread,
Apr 16, 2018, 3:18:47 PM4/16/18
to
I forgot to ask whether you wanted to change the background of the
entry field or the listbox. For a ttk::combobox, the ttk::style options
generally work on the entry field. But it's a bit confused, as there are
multiple elements in the ttk::combobox (entry field, arrow, listbox).

There is a writeup here: http://wiki.tcl.tk/37973
that I worked on, on how to change colors for various widgets.

The example below changes all the background colors to cyan:

-background changes the base background, and that will show as the background
of the arrow.

-fieldbackground changes the entry field's background (for state: normal).

The 'ttk::style map' command with -fieldbackground changes the entry field's
background when it is in the readonly state.

And the 'option add' command changes the listbox's background.



package require Tk

ttk::style theme use default

set category_list {student ex_student visitor collaborator}

set category_pt student

ttk::combobox .category \
-textvariable category_pt \
-state readonly \
-values $category_list

ttk::style configure TCombobox -background cyan
ttk::style configure TCombobox -fieldbackground cyan
ttk::style map TCombobox -fieldbackground [list readonly cyan]
option add *TCombobox*Listbox.background cyan
pack .category

Markos

unread,
Apr 18, 2018, 9:34:58 AM4/18/18
to
Hi Brad,

In my case the command

ttk::style map TCombobox -fieldbackground [list readonly white]

was enough to configure with the color I wanted.

And I also used the commands (from http://wiki.tcl.tk/37973):

ttk::style configure TCombobox -selectbackground white
ttk::style configure TCombobox -selectforeground black

These three commands were sufficient to set the desired configuration.

Thank you very much for your help.

Best Regards,
Markos
0 new messages