问题
I try to style a tkinter gui, first this gui is not easy to modify. I reach the styling i want for the widgets i use, except for one think. I get lock about this light gray border around the Menu in the ttk.OptionMenu widget.
How removing or coloring it ?
Python 3x on Windows 10
Here just the relevant parts of the code.
Some common styling:
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)
The styling for the widget:
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")])
The OptionMenu and is Menu:
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)
Result:
Thanks.
Addition:
@stovfl Sorry in my first post i have remove the lines do not have any effects on the result, so, your new comment make me understand i should not. So, the commented lines don't have any effects.
And to be complete, as you can see in the original post, "highlightsickness| borderwidth | activeborderwidth" was already used.
And to be really complete highlightthickness=0 looks like don't have effects too, but it was not commented in my first post.
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)])
And here, each of the commented lines produce an error.
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)
Thanks.
Addition:
This program is not an private test for learning, it is for my work. It is my first attempts to use tkinter. Also, i never have need to try to do gui in python before. The program work well and do all i was supposed to implement. The point here is just aesthetic and styling detail for this strange border. I always browse Stackoverflow it is rich source of information, that why i decide to create an account and post my first question here.
Thanks.
@stovfl Yes me too i was hoping in this options, but the borderwidth and activeborderwidth are option of the menu and affect some inner borders of the menu, not the outer one.
To show the effect of borderwidth i use exagerate value at 50:
@stovfl The reult of the print.
{'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'>),
In my environment the boder color is black
and with borderwidth=0
no border is shown.
来源:https://stackoverflow.com/questions/60949887/ttk-optionmenu-outer-border-around-the-menu