I'm trying to make application with Notebook Tabs, but each tab should be described separately as class. For start I gave 2 classnames for 2 tabs as Frame1 and Frame2, but I want to give sensible names. Here is the code that works:
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry('400x400')
root.title('Title')
notebook = ttk.Notebook(root)
class Frame1(Frame):
def __init__(self, container):
super().__init__(container)
self.Frame1 = Frame(container)
self.Frame1.config(bg='blue')
self.Frame1.place(x=0, y=24, relwidth=0.9, relheight=0.9)
class Frame2(Frame):
def __init__(self, container):
super().__init__(container)
self.Frame2 = Frame(container)
self.Frame2.config(height=200, width=203, bg= 'green')
self.Frame2.place(x=0, y=24)
Frame1 = Frame1(notebook)
notebook.add(Frame1, text = "Connection")
Frame2 = Frame2(notebook)
notebook.add(Frame2, text = "Transient Response")
notebook.place(x=10, y=10)
root.mainloop()
Result is on screenshot - 2 tabs with blue and green filling. I want to give sensible names. As soon as I change class name, e.g. Frame2 for Frame3, picture spoils (see screenshot).
Frame1
object (for example) is a Frame, but it also creates an entirely separate Frame namedself.Frame1
. The former is what you actually add to your notebook, but the latter is what you're setting the color of. You either need to get rid of this extra Frame completely, or make it contained by the actual Frame in the notebook (Frame(self)
instead ofFrame(container)
).self.frame
in both classes instead ofself.Frame1
andself.Frame2
- and for me this is"sensible name"