[英]How to change the color of the dropdown text color of ttk combobox widget?
首先我只是嘗試使用:
missed_list_combobox.config(foreground="red")
然后我試圖設置新的風格:
style_missed_combobox = tkinter.ttk.Style()
style_missed_combobox.configure("Red.TCombobox", foreground="red")
並在創建 combobox 小部件后使用它。
missed_list_combobox = tkinter.ttk.Combobox(frame4, state="readonly", width=32, style="Red.TCombobox")
missed_list_combobox.grid(row=2, column=3, padx=2, sticky="w", pady=3)
但同樣...它只是更改 combobox 中頂部元素的顏色...而不是整個下拉元素...如何更改所有下拉元素的顏色文本...?
提前致謝, eliran
據我所知,tkinter 無法直接實現這一點,因為我們無法通過 python 接口訪問組合框的列表框。 然而,這可以使用底層 tcl 解釋器來完成:
missed_list_combobox.tk.eval('[ttk::combobox::PopdownWindow %s].f.l configure -foreground red' % missed_list_combobox)
如果你還想把背景改成黃色,只需在上面的 tcl 命令中加上-background yellow
即可。
順便說一句,如果你想改變所有組合框的下拉列表框的默認前景,你可以使用
root.option_add('*TCombobox*Listbox.foreground' % frame, 'red')
但這僅適用於在此行之后創建的組合框( root
可以被任何小部件替換)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.