【发布时间】:2021-02-14 18:47:05
【问题描述】:
我一直在尝试创建一个适合我的 UI 其余部分的组合框;但是小部件仍然看起来像默认值:
在我的尝试中,我尝试使用以下代码“强制”小部件适应颜色,但无济于事:
self.root = tk.Tk() # Parent Container
# Other UI elements declared
self.themeSel_combo_theme.configure(
"TCombobox",
background=self.theme.get('bg'),
foreground=self.theme.get('bg'),
fieldbackground=self.theme.get('bg'),
darkcolor=self.theme.get('bg'),
lightcolor=self.theme.get('bg'),
selectbackground=self.theme.get('bg'),
selectforeground=self.theme.get('bg'),
bordercolor=self.theme.get('bg'),
insertcolor=self.theme.get('bg'),
insertwidth=self.theme.get('bg'), # It uses a color, not a size value
arrowcolor=self.theme.get('bg')
)
self.themeSel_combo = ttk.Combobox(self.quickTheme_cont, style="TCombobox")
上面的代码是使用this website作为参考编写的。
注意self.theme.get('bg') 返回#202020
【问题讨论】:
-
你确定所有这些样式的组合框都可以改变吗?
-
@CoolCloud,是的;正如我所说,我使用的参考资料说所有这些都是 ttk::combobox 小部件的有效选项
-
也许可以给出一个可重现的例子,以便我们试一试。
-
对给您带来的不便深表歉意;经过一些研究,我发现使用
tk.Tk()会导致ttk对象的样式不正确;因此我不得不将其更改为tk.Toplevel()
标签: python python-3.x tkinter tk ttk