tkinter (ttk) combobox dropdown text is white on white

Peter Otten __peter__ at web.de
Tue Jun 5 03:21:58 EDT 2018


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.





More information about the Python-list mailing list