删除Ttk笔记本电脑的标签虚线
我正在尝试制作看起来不像tkinter应用程序的tkinter应用程序。我使用的是ttk笔记本,并且在选中选项卡时,这些选项在文本的周围都有一点点虚线。它看起来很糟糕,我找不到使用样式或配置删除它的方法。这是要说明的屏幕截图:
编辑代码(我认为这不会有很大帮助,因为我实际上只是在尝试删除默认样式的东西。):
这是笔记本的创建:
tabs = ttk.Notebook(mainframe, width=319, height=210, style=style.Notebook)
tabs.grid(column=0, row=1, sticky=('n', 'w', 'e', 's'))
tabs.columnconfigure(0, weight=1)
tabs.rowconfigure(0, weight=1)
填写:
tab1 = ttk.Frame(tabs)
tab1_frame = ttk.Frame(tab1, style=style.Frame)
tab1_frame.pack(anchor='center', expand=1, fill='both')
# stick some widgets in
progress = ttk.Progressbar(tab1_frame, orient="horizontal", length=300, mode="determinate")
progress.grid(column=1, row=1, columnspan=2, padx=style.padding, pady=style.padding)
progress['maximum'] = 1000
progress['value'] = 500
# More widgets
# Another tab
tab2 = ttk.Frame(tabs)
tab2_frame = ttk.Frame(tab2, style=style.Frame)
tab2_frame.pack(anchor='center', expand=1, fill='both')
# blah blah
相关样式:
style_config = Style()
style_config.theme_use('default')
style_config.configure(self.Notebook,
background=self.dark,
borderwidth=0)
style_config.configure(self.Tab,
background=self.dark,
foreground='white',
padding=self.padding,
borderwidth=0)
style_config.map(self.Tab,
background=[('selected', self.color1)])
-
您可以通过更改选项卡小部件的子元素来删除此焦点标记。Ttk小部件分解为子元素。这些元素的布局通过
layout
方法(或在的布局参数中theme_create
)进行描述。这是删除布局标记的命令(您可以将其直接应用于Tab或任何其他派生的主题),注释的部分是导致绘制焦点的原因(通过检索style.layout("Tab")
)style.layout("Tab", [('Notebook.tab', {'sticky': 'nswe', 'children': [('Notebook.padding', {'side': 'top', 'sticky': 'nswe', 'children': #[('Notebook.focus', {'side': 'top', 'sticky': 'nswe', 'children': [('Notebook.label', {'side': 'top', 'sticky': ''})], #})], })], })] )
一种更怪异的方法可能是更改此焦点的颜色,例如将其绘制为与背景相同的颜色
style.configure("Tab", focuscolor=style.configure(".")["background"])