мalay мeнтa
мalay мeнтa

Reputation: 145

How to get frame name of notebook widget in tkinter

If we have label than we have an option to get it's text as

l = tk.Label(text="hello, world")
...
print("the label is", l.cget("text"))

But I am unable to find a name of frame added in notebook by the same way is there any other approach available?

ttk.Notebook sample:

import tkinter
from tkinter import *
from tkinter.ttk import *
root = tkinter.Tk()
note = Notebook(root)

tab2 = Frame(note)
tab3 = Frame(note)

note.add(tab2, text = "Tab Two")
note.add(tab3, text = "Tab Three")
note.pack()
root.mainloop()
exit()

Upvotes: 3

Views: 3188

Answers (2)

Kathryn
Kathryn

Reputation: 41

You can give widgets names when you create them:

note = Notebook(root, name="George")
tab2 = Frame(note, name="Tabby")

and find widgets by name using nametowidget:

tab2 = root.nametowidget("George.Tabby")

Upvotes: 4

Nae
Nae

Reputation: 15345

You can get the text option of a tab of a ttk.Notebook by:

note.tab(tab2)['text']

more generally you can get the option of a tab by:

nb.tab(tab_name)[option]

Upvotes: 1

Related Questions