S
S
Sheud_z2021-08-09 16:37:36
Python
Sheud_z, 2021-08-09 16:37:36

Is it possible to use ttk.notebook in ttk.notebook?

Is it possible to use ttk.Notebook in ttk.Notebook?

For example, I will provide the following code:

tab_control = ttk.Notebook(root)
tab1 = ttk.Frame(tab_control)  
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='TEST1')
tab_control.add(tab2, text='TEST2')

rage_par = ttk.Notebook(tab2)
tab11 = ttk.Frame(rage_par)  
tab22 = ttk.Frame(rage_par)
tab_control.add(tab11, text='TEST')
tab_control.add(tab22, text='TEST')

tab_control.pack(expand=1, fill='both')
tab_control.place(x=0, y=30)

rage_par.pack(expand=1, fill='both')
rage_par.place(x=0, y=80)

the code gives the following error:

self.tk.call(self._w, "add", child, *(_format_optdict(kw)))
_tkinter.TclError: can't add .!notebook.!frame5.!notebook.!frame as slave of .!notebook

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor T2, 2021-08-09
@Viktor_T2

Firstly, you use two geometry managers at once, pack and place,
- this is not correct, leave one of the two.
Secondly, you are confused about what you are inserting into.
Here is a working one:

spoiler
import tkinter as tk
from tkinter import ttk

root = tk.Tk()
root.geometry('600x400+200+100')

tab_control = ttk.Notebook(root)
tab1 = ttk.Frame(tab_control)
tab2 = ttk.Frame(tab_control)
tab_control.add(tab1, text='TEST1')
tab_control.add(tab2, text='TEST2')


rage_par = ttk.Notebook(tab1)
tab11 = ttk.Frame(rage_par)
tab22 = ttk.Frame(rage_par)
rage_par.add(tab11, text='TEST')   # вот где лажа
rage_par.add(tab22, text='TEST')


tab_control.pack(expand=1, fill='both')
# tab_control.place(x=0, y=30)

rage_par.pack(expand=1, fill='both')


root.mainloop()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question