我尝试设计一个tkinter gui,首先这个gui不容易修改。 我使用的小部件达到了我想要的样式,除了一个想法。 我在ttk.OptionMenu小部件的菜单周围锁定了浅灰色边框
如何去除或着色
Windows10上的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")])
选项菜单和is菜单:
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)
结果:
谢谢
补充:
@stovfl很抱歉,在我的第一篇帖子中,我删除了这些行,对结果没有任何影响,因此,你的新评论让我明白我不应该这样做。因此,注释行没有任何效果
完整地说,正如您在原始帖子中看到的,“HighlightSick | 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是菜单的选项,影响菜单的一些内部边框,而不是外部边框
为了显示borderwidth的效果,我在50处使用exagerate值:
@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'>),
在我的环境中,boder颜色是black
,并且borderwidth=0
没有显示边框
目前没有回答
相关问题 更多 >
编程相关推荐