My problem is in the question. Because I get this : _tkinter.TclError: can't put .!notebook.!frame.!frame.!notebook inside .!notebook.!frame.!frame, would cause management loop
from tkinter import *
from tkinter import ttk
class Agenda(Frame):
def __init__(self, master):
Frame.__init__(self, master=None)
self.master = master
self.notebook = ttk.Notebook(self.master)
self.frames = []
self.cadres = []
self.horaires = ["7 heures", "8 heures", "9 heures", "10 heures", "11 heures"]
self.notes = []
self.frames_horaires=[]
def creer_onglets(self, liste):
for i in range(len(liste)):
self.frames.append(ttk.Frame(self.notebook))
self.notebook.add(self.frames[i], text=liste[i])
self.notebook.pack()
self.cadres.append(ttk.Frame(self.frames[i]))
self.cadres[i].pack(anchor='nw', expand=True)
self.notes.append(ttk.Notebook(self.cadres[i]))
for j in range(len(self.notes)):
for k in range(len(self.horaires)):
self.frames_horaires.append(ttk.Frame(self.notes[i]))
self.notes[i].add(self.frames[i], text=self.horaires[i])
self.notes[i].pack()
ttk.Label(self.cadres[i], text=f"Jour {i+1} de la semaine", background='lightblue').pack()
if __name__ == '__main__':
root = Tk()
root.title('Test de Notebook')
agenda = Agenda(root)
jours = ['Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'vendredi', 'Samedi', 'Dimanche']
agenda.creer_onglets(liste=jours)
root.mainloop()
There are several problems with this code. You have two nested loops within the main loop, which is unnecessary and the index variables
jandkare not accessed. Your code is creating multiple tabs for the same time slot within each notebook.self.frames_horairesgets 5 elements on each iteration of the main loop but only the element at indexiis accessed to create the tab for time slot. Also you are calling pack methods forself.notebookandself.notes[i]within the loops, which is also not correct. Here is a modified code that works.Below is the screenshot: