简体   繁体   中英

How do I hide the entire tab bar in a tkinter ttk.Notebook widget?

How do I hide the tab bar in a ttk Notebook widget? I don't want to hide the frame that belongs to the tab. I just want to remove the tab bar from sight, even where it's not at the top of the screen (for more than one purpose).

Anyway, it would be nice for fullscreen mode.

from the help on tkinter.ttk.Style:

layout(self, style, layoutspec=None)

Define the widget layout for given style. If layoutspec is omitted, return the layout specification for given style.

layoutspec is expected to be a list or an object different than None that evaluates to False if you want to "turn off" that style.

try this:

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

style = ttk.Style()

style.layout('TNotebook.Tab', []) # turn off tabs

note = ttk.Notebook(root)

f1 = ttk.Frame(note)
txt = tk.Text(f1, width=40, height=10)
txt.insert('end', 'Page 0 : a text widget')
txt.pack(expand=1, fill='both')
note.add(f1)

f2 = ttk.Frame(note)
lbl = tk.Label(f2, text='Page 1 : a label')
lbl.pack(expand=1, fill='both')
note.add(f2)

note.pack(expand=1, fill='both', padx=5, pady=5)

def do_something():
    note.select(1)
               
root.after(3000, do_something)
root.mainloop()

In order to hide the tab bar for a specific notebook (and not all notebooks in your app) you have to create a new style with tabs turned off and assign it to just that notebook when you create it (as described here ).

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

style = ttk.Style()

style.layout('Tabless.TNotebook.Tab', []) # new style with tabs turned off

note = ttk.Notebook(root, style='Tabless.TNotebook') # w/o the .Tab

f1 = ttk.Frame(note)
txt = tk.Text(f1, width=40, height=10)
txt.insert('end', 'Page 0 : a text widget')
txt.pack(expand=1, fill='both')
note.add(f1)

f2 = ttk.Frame(note)
lbl = tk.Label(f2, text='Page 1 : a label')
lbl.pack(expand=1, fill='both')
note.add(f2)

note.pack(expand=1, fill='both', padx=5, pady=5)

def do_something():
    note.select(1)
               
root.after(3000, do_something)
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM