删除 Ttk Notebook Tab 虚线 [英] Removing Ttk Notebook Tab Dashed Line

查看:36
本文介绍了删除 Ttk Notebook Tab 虚线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个看起来不像 tkinter 应用程序的 tkinter 应用程序.我正在使用 ttk Notebook,当它们被选中时,选项卡在文本周围有这条小虚线.它看起来很糟糕,我找不到使用样式或配置删除它的方法.这是一个屏幕截图以澄清:

I'm trying to make a tkinter app that doesn't look like a tkinter app. I'm using a ttk Notebook, and the tabs have this little dotted line around the text when they're selected. It looks terrible, and I can't find a way to remove it using either styles or config. Here's a screenshot to clarify:

编辑代码(我认为这不会很有帮助,因为我实际上只是想删除默认样式的东西.):

Edit for code (I don't think it'll be terribly helpful, since I'm actually just trying to remove a default style thing.):

这是笔记本的创建:

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")<检索)/code>)

You can remove this focus mark by altering the sub elements of tab widget. Ttk widgets are decomposed in subelements. The layout of these elements is described through layout method (or in a layout parameter of theme_create). Here is a command to remove layout marks (you can apply it directly to Tab, or any other derived theme), the commented part is what lead previously to drawing the focus (retrieved through 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': ''})],
        #})],
    })],
})]
)

一种更hacky的方法可能是改变这个焦点标记的颜色,例如把它画成与背景相同的颜色

A more hacky way could be to alter the color of this focus mark, for instance to draw it the same color as background

style.configure("Tab", focuscolor=style.configure(".")["background"])

这篇关于删除 Ttk Notebook Tab 虚线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆