【问题标题】:TTK Combobox does not style properlyTTK 组合框样式不正确
【发布时间】: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


【解决方案1】:

对给您带来的不便深表歉意;我决定保留这个线程,以防其他人需要帮助。事实证明,使用以下命令创建父容器会导致 ttk 对象的样式不正确:

self.root = tk.Tk()

将上述命令更改为以下命令解决了我遇到的问题:

self.root = tk.Toplevel()

【讨论】:

    猜你喜欢
    • 2015-11-05
    • 1970-01-01
    • 2020-09-15
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 2011-01-28
    • 2010-12-14
    • 1970-01-01
    相关资源
    最近更新 更多