tkinter (ttk) combobox dropdown text is white on white

Jim Lee jlee54 at gmail.com
Tue Jun 5 12:19:35 EDT 2018



On 06/05/2018 12:21 AM, Peter Otten wrote:
> Jim Lee wrote:
>
>> Oops, I hit "reply" instead of "reply-list" last time.  Trying again...
>>
>>
>> On 06/03/2018 02:01 PM, Christian Gollwitzer wrote:
>>> Am 03.06.18 um 21:54 schrieb Jim Lee:> import tkinter as tk
>>>> from tkinter import ttk
>>>>
>>>> root = tk.Tk()
>>>> cb = ttk.Combobox(root)
>>>> cb.grid(row=0, column=0, sticky='NSEW')
>>>> cb['values'] = ['one', 'two', 'three', 'four']
>>>> root.mainloop()
>>>>
>>>> The text of the values in the combobox dropdown list is white on
>>>> white.   The *selected* item in the list is white on light grey, but
>>>> all the unselected items are invisible (white on white).
>>> Which platform are you on, i.e. which operating system? I guess it is
>>> Linux. In that case the default colors are read by Tk from the X11
>>> options database, which is some cruft from the past to set options for
>>> X11 applications. Try to run
>>>
>>> xrdb -query
>>>
>>> That should give you a list of default values, and maybe you can see
>>> something. The dropdown list is actually a popdown menu, so look for
>>> Menu colors. For instance, if you use a dark theme in your desktop
>>> environment, it could be that the foreground is correctly set to
>>> white, but the background is hardcoded white for some reason e.g.
>>>
>>>
>>> Christian
>> Thanks.  Yes, I am on Linux (Fedora 28, MATE desktop).  Yes, I am using
>> a dark theme - however, xrdb does not show #ffffff for *any* background
>> color, so I have no idea where ttk is picking it up from.  Even if I
>> change to a light desktop theme, the ttk widget still displays white on
>> white.  The only solution I have found so far is rather hackish, but it
>> works:
>>
>> class MyCombobox(ttk.Combobox):
>>   def __init__(self, *args, **kwargs):
>>   super().__init__(*args, **kwargs)
>>   self.bind('<Map>', self._change_popdown_color)
>>
>>   def _change_popdown_color(self, *args):
>>   popdown = self.tk.eval('ttk::combobox::PopdownWindow
>> {}'.format(self))
>>   self.tk.call('{}.f.l'.format(popdown), 'configure',
>> '-foreground', 'black')
>>
>> However, I am still looking for a more elegant solution that preferably
>> doesn't hardcode colors...
> import tkinter as tk
> from tkinter import ttk
>
> root = tk.Tk()
> root.option_add('*TCombobox*Listbox.foreground', "black")
>
> cb = ttk.Combobox(root)
> cb.grid(row=0, column=0, sticky='NSEW')
> cb['values'] = ['one', 'two', 'three', 'four']
> root.mainloop()
>
> The foreground color is still hardcoded, but the extra code is a little less
> invasive.
>
>
Thanks for that - it's certainly cleaner.  I'm finding that ttk (at 
least as wrapped by tkinter) is fairly buggy - many of the options 
(particularly sytle-related ones) are order dependent, while others are 
ignored entirely.  For example, behavior is different if you set the 
foreground color before the background vs. the other way around.  Also, 
I've found that changing combobox colors in a certain order will affect 
the appearance of buttons ?!?  I think it's time to look for a different 
Python GUI...

-Jim Lee




More information about the Python-list mailing list