如何在tkinter python中删除tabMenu上的虚线

问题描述

enter image description here

如您所见,在单击 tabMenu 后,每个 tabMenu 都有虚线 如何删除这条虚线? 底部是源代码谢谢。

    from tkinter import *
    from tkinter import ttk

    tabposition = ttk.Style()
    tabposition.configure('TNotebook',sticky='w',tabposition='sw')
    
    style = ttk.Style()
    
    tabposition.configure("Tab",focuscolor=style.configure(".")["background"])
    
    notebook = ttk.Notebook(root,width=1450,height=910)
    notebook.pack(fill="y",expand=False)
    notebook.place(x=526)

    def newtab2():
        frame0 = Frame(root)
        notebook.add(frame0,text="First Input")

    addSheet = Button(root,text="Enter",command=newtab2,borderwidth=1)
    addSheet.place(x=10,y=159,width=41,height=41)

解决方法

有几点要说:

  1. 当您想将框架添加到 ttk.Notebook 时,请将其用作框架的。在您的代码中,它被赋予了 root

  2. 无需使用新的 ttk.Style()。相反,设置原始 ttk.Style()

    的布局

下面给出的是更正后的代码。请注意,ttk.Notebook 的高度由我更改。您可以稍后更改。

from tkinter import *
from tkinter import ttk
root=Tk()
tabposition = ttk.Style()
tabposition.configure('TNotebook',sticky='w',tabposition='sw')
notebook = ttk.Notebook(root,width=1450,height=510)
notebook.pack(fill="both",expand=1)
tabposition.layout("Tab",[('Notebook.tab',{'sticky': 'nswe','children':
    [('Notebook.padding',{'side': 'top','sticky': 'nswe','children':
        #[('Notebook.focus','children':
            [('Notebook.label','sticky': ''})],#})],})],})]
)
def newtab2():
    frame0 = Frame(notebook)
    notebook.add(frame0,text="First Input")
addSheet = Button(root,text="Enter",command=newtab2,borderwidth=1)
addSheet.place(x=10,y=159,width=41,height=41)
root.mainloop()

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...