[英]Removing Ttk Notebook Tab Dashed Line
我正在嘗試制作一個看起來不像 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"])
在Windows機器上,如果我創建主題並使用“經典”作為父級,則也不會繪制丑陋的虛線邊框。
style.theme_create( "Florina", parent="classic", settings={
"TLabel": {"configure": {"background": BACKGROUND }},
"TFrame": {"configure": {"background": BACKGROUND }},
"TNotebook": {
"configure": {"background": BACKGROUND, "tabmargins": [1, 5, 2, 0] }},
"TNotebook.Tab": {
"configure": {"background": DARKBG, "padding": [5, 2] },
"map": {"background": [("selected", BACKGROUND)],
"expand": [("selected", [1, 1, 1, 0])]
} } } )
您可以使用theme_create()
更改焦點顏色:
wthm = ttk.Style()
wthm.theme_create('wtheme', parent='default', settings={
'TNotebook.Tab': {
'configure': {'focuscolor':{
'configure':{
'.':'<your_color>'}
}}
})
wthm.theme_use('wtheme')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.