I'm trying to generalize the addition of buttons and tabs in a tkinter.ttk.Notebook
. Here's what I have so far:
from tkinter.ttk import Notebook, Frame
from tkinter import Button, Tk
f1 = lambda: print("f1")
f2 = lambda: print("f2")
f3 = lambda: print("f3")
f4 = lambda: print("f4")
f5 = lambda: print("f5")
f6 = lambda: print("f6")
f7 = lambda: print("f7")
frames = ["F1", "F2", "F3"]
labels = [('f1', 'f2', 'f3'), ('f4', 'f5'), ('f6', 'f7')]
commands = [(f1, f2, f3), (f4, f5), (f6, f7)]
tk = Tk()
notebook = Notebook(tk)
for i, f in enumerate(frames):
frame = Frame(notebook)
notebook.add(frame, text=f)
for j, label in enumerate(labels[i]):
button = Button(frame, text=label, command=commands[i][j])
button.pack()
notebook.pack()
tk.mainloop()
Now, suppose I want function f7
not to print the string 'f7'
, but rather to perform a frame.quit
so I can exit out of the notebook.
How can I call frame.quit
and keep the generic nature of the code above?
I don't know how I could do that before the for
loop.