hide forget and select methods of Notebook tab

Tkinter Notebook

ttk Notebook hide destroy select options

Tkinter Notebook methods to select hide forget tabs and using notebook tab change event


On Click of buttons we will execute different methods. These codes are connected to buttons. Four different buttons are used and On click of the buttons we are executing hide(), add() , forget() and select() methods of Notebook.
b3=tk.Button(my_w,text='hide t-1',command=lambda:my_tabs.hide(tab1))
b3.pack(side=LEFT)
b4=tk.Button(my_w,text='add t-1',command=lambda:my_tabs.add(tab1))
b4.pack(side=LEFT)
b5=tk.Button(my_w,text='forget t-1',command=lambda:my_tabs.forget(tab1))
b5.pack(side=LEFT)
b6=tk.Button(my_w,text='select t-1',command=lambda:my_tabs.select(tab1))
b6.pack(side=LEFT)
Full code is here
import tkinter  as tk 
from tkinter import *
from tkinter import ttk
my_w = tk.Tk()
my_w.geometry("400x200")  
my_tabs = ttk.Notebook(my_w,padding=10) # declaring 

tab0 = ttk.Frame(my_tabs)
tab1 = ttk.Frame(my_tabs)
tab2 = ttk.Frame(my_tabs)

my_tabs.add(tab0, text ='Tab-0') # adding tab
my_tabs.add(tab1, text ='Tab-1') # adding tab 
my_tabs.add(tab2, text ='Tab-2') # adding tab 
my_tabs.pack(expand = 1, fill ="both")

font1=('time',22,'normal')
l1=tk.Label(tab0,text='I am tab-0',bg='yellow',font=font1)
l1.place(relx=0.4,rely=0.2) # using place
l2=tk.Label(tab1,text='I am tab-1',bg='yellow',font=font1)
l2.place(relx=0.4,rely=0.2) # using grid 
l3=tk.Label(tab2,text='I am tab-2',bg='yellow',font=font1)
l3.place(relx=0.4,rely=0.2) # using place

b3=tk.Button(my_w,text='hide t-1',
    command=lambda:my_tabs.hide(tab1))
b3.pack(side=LEFT)
b4=tk.Button(my_w,text='add t-1',
    command=lambda:my_tabs.add(tab1))
b4.pack(side=LEFT)
b5=tk.Button(my_w,text='forget t-1',
    command=lambda:my_tabs.forget(tab1))
b5.pack(side=LEFT)
b6=tk.Button(my_w,text='select t-1',
    command=lambda:my_tabs.select(tab1))
b6.pack(side=LEFT)

my_w.mainloop()  # Keep the window open

Notebook

Tab option state Tab Option sticky Tab Option underline
On Tab change event to display Tab Number

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here





    Python Video Tutorials
    Python SQLite Video Tutorials
    Python MySQL Video Tutorials
    Python Tkinter Video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer