Problems Remains inserting two different classes within the same frame into a notebook using Tkinter and Python Problems Remains inserting two different classes within the same frame into a notebook using Tkinter and Python tkinter tkinter

Problems Remains inserting two different classes within the same frame into a notebook using Tkinter and Python


You've got way too many bugs in this code for us to help you. Let me give you some advice since you're obviously struggling: Don't try to build your whole app at once. Focus on one part at a time, get it right, and then move on.

For example, start over with your app and create the main window and the notebook, and nothing else. Get that part working. Create a dummy frame for your two notebook tabs just to prove that you have the notebook working and you understand how to add tabs. Don't do anything else until this simple program works, resizes, starts and stops like you expect. Give every widget you create a distinctive background color so that you can visually see each widget.

For example:

import Tkinter as tkimport ttkroot = tk.Tk()notebook = ttk.Notebook(root)notebook.pack(fill="both", expand=True)tab1 = tk.Frame(notebook, background="red")tab2 = tk.Frame(notebook, background="green")notebook.add(tab1, text="Tab 1")notebook.add(tab2, text="Tab 2")root.mainloop()

Let me emphasize: don't do anything else until you have that working and understand what the code is doing

Once you are satisfied with that, you can now focus on one of the tabs. Each tab starts with a frame, so create a function that creates just the frame. Have this function return the frame rather than pack or grid the frame in the parent. As a rule of thumb you should never have a function or class pack/grid itself in its parent, because it makes your code hard to understand and modify. Make each frame a self-contained thing, and let the code that creates it decide how to lay it out. Believe me, it is much easier to write a GUI this way.

For example:

def tab1(parent):    frame = tk.Frame(parent, background="pink")    return frame

Then modify your code to be like this:

import Tkinter as tkimport ttk<put your definition of tab1 here...>root = tk.Tk()notebook = ttk.Notebook(root)notebook.pack(fill="both", expand=True)tab1 = tab1(notebook)tab2 = tk.Frame(notebook, background="green")notebook.add(tab1, text="Tab 1")notebook.add(tab2, text="Tab 2")root.mainloop()

Ok, now stop, run that code, and make sure you understand what happened. Is it all still working? Now, in the blank line in tab1, you can add all the widgets for this container. You can pack or grid them inside the frame, you don't have to pass all of those up. You only pass the container up to the caller. Eventually you can learn how to create a subclass of tk.Frame instead of using a function, but don't worry about that now. If you follow this style of coding, switching to an object oriented style in the future will be pretty painless.

Continue on working like this, building up one piece at a time. Stop as often as you can and run the code, making sure it still resizes properly and is laid out the way you want. Tackle each section separately, and eventually it will all work wonderfully together.