ttk.OptionMenu菜单周围的外边框

时间:2020-03-31 11:49:35

标签: python windows tkinter tkinter.optionmenu tkinter.style

我尝试设置tkinter gui的样式,首先,此gui不容易修改。 我达到了我想要使用的小部件的样式,除了一种想法。 我对ttk.OptionMenu小部件中Menu周围的浅灰色边框有误。

如何删除或着色?

Windows 10上的Python 3x

这里只是代码的相关部分。

一些常见样式:

self.style = ttk.Style(self)
self.style.theme_use("clam")

self.font12 = tkFont.Font(family="helvetica", size=12)
self.font14 = tkFont.Font(family="helvetica", size=14)

master.option_add("*font", self.font12)
master.option_add("*background", self.bgc)
master.option_add("*foreground", self.fgc)

小部件的样式:

master.option_add("*Menu.background", self.dbgc)

self.style.configure("TMenubutton", relief=tk.FLAT, font=self.font14, bd=0, highlightthickness=0,
        arrowcolor="#909090", foreground=self.dfgc, background=self.dbgc)
self.style.map("TMenubutton",
        background=[('disabled', self.dbgc),('pressed', self.abgc), ('active', self.abgc)],
        foreground=[('disabled', "#707070")])

OptionMenu也是菜单:

om3 = ttk.OptionMenu(self.top_frame, self.var_quality,
    qualities['u'], *['UltraQuality','High','Normal','Preview'])
om3.pack(side=tk.LEFT, padx=4)
om3['width'] = 10
om3['menu'].configure(relief=tk.FLAT, font=self.font12,
    borderwidth=1, activeborderwidth=5,  activeforeground=self.afgc,
    activebackground=self.abgc, selectcolor=self.fgc)

结果:

OptionMenu and Menu

谢谢。

添加:

@stovfl 抱歉,在我的第一篇文章中,我删除了这些行对结果没有任何影响,因此,您的新评论使我明白我不应该这样做。因此,注释行没有任何作用。

为了完整起见,正如您在原始帖子中看到的那样,已经使用了“ highlightsickness | borderwidth | activeborderwidth”。

要真正完整地做到,highlightthickness = 0似乎也没有影响,但是我的第一篇文章中没有对此发表评论。

self.style.configure("TMenubutton", relief=tk.FLAT, font=self.font14, bd=0, highlightthickness=0,
    # bordercolor=self.dbgc, focusthickness=0, focuscolor=self.dbgc,
    arrowcolor="#909090", foreground=self.dfgc, background=self.dbgc)
self.style.map("TMenubutton",
    background=[('disabled', self.dbgc),('pressed', self.abgc), ('active', self.abgc)],
    foreground=[('disabled', "#707070")],
    # focuscolor=[('disabled', self.dbgc), ('active', self.dbgc)])

# self.style.configure("TMenu", highlightthickness=0, bordercolor=self.dbgc, 
#     focusthickness=0, focuscolor=self.dbgc)
# self.style.map("TMenu",
#     highlightbackground=[('disabled', self.dbgc), ('active', self.dbgc)],
#     highlightcolor=[('disabled', self.dbgc), ('active', self.dbgc)],
#     focuscolor=[('disabled', self.dbgc), ('active', self.dbgc)])

在这里,每条注释行都会产生错误。

om3 = ttk.OptionMenu(self.top_frame, self.var_quality,
    qualities['u'], *['UltraQuality','High','Normal','Preview'])
om3.pack(side=tk.LEFT, padx=4)
om3['width'] = 10
om3['menu'].configure(relief=tk.FLAT, font=self.font12,
    # focuscolor=self.dbgc,
    # focusthickness=0,
    # bordercolor=self.dbgc,
    # highlightthickness=0,
    borderwidth=1, activeborderwidth=5,  activeforeground=self.afgc,
    activebackground=self.abgc, selectcolor=self.fgc)

谢谢。

添加:

该程序不是学习的私人考试,而是我的工作。这是我第一次尝试使用tkinter。另外,我从来没有必要尝试在python中做gui。该程序运行良好,可以完成我应该执行的所有操作。 这里的重点只是这个奇怪边框的美学和样式细节。 我总是浏览Stackoverflow,它提供了丰富的信息,这就是为什么我决定创建一个帐户并将我的第一个问题发布在这里的原因。

谢谢。

@stovfl 是的,我也希望使用此选项,但是borderwidth和activeborderwidth是菜单的选项,会影响菜单的某些内部边框,而不是外部边框。

为显示边界宽度的影响,我使用exagerate值为50:

enter image description here


@stovfl 打印结果。

{'activebackground': ('activebackground', 'activeBackground', 'Foreground', <string object: 'SystemHighlight'>, <string object: '#606060'>),
'activeborderwidth': ('activeborderwidth', 'activeBorderWidth', 'BorderWidth', '0', 5),
'activeforeground': ('activeforeground', 'activeForeground', 'Background', <string object: 'SystemHighlightText'>, <string object: '#ffffff'>),
'background': ('background', 'background', 'Background', 'SystemMenu', <string object: '#353535'>),
'bd': ('bd', '-borderwidth'),
'bg': ('bg', '-background'),
'borderwidth': ('borderwidth', 'borderWidth', 'BorderWidth', '0', 1),
'disabledforeground': ('disabledforeground', 'disabledForeground', 'DisabledForeground', <string object: 'SystemDisabledText'>, <string object: '#606060'>),
'fg': ('fg', '-foreground'),
'foreground': ('foreground', 'foreground', 'Foreground', 'SystemMenuText', <string object: '#dddddd'>),
'relief': ('relief', 'relief', 'Relief', 'flat', <string object: 'flat'>),
'selectcolor': ('selectcolor', 'selectColor', 'Background', <string object: 'SystemMenuText'>, <string object: '#dddddd'>),

enter image description here
在我的环境中,boder的颜色为black,使用borderwidth=0时则不会显示边框。


0 个答案:

没有答案