问题描述
如您所见,在单击 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)
解决方法
有几点要说:
-
当您想将框架添加到
ttk.Notebook
时,请将其用作框架的主。在您的代码中,它被赋予了root
-
无需使用新的
的布局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()