0

I may not understand inheritance very well, or I might have missed some details about it. I was reading https://stackoverflow.com/a/40130619/5989438, and thought I need to do it this way, however it's not working.

I have a complete program in the Application() class, which is located in tab "Week_1". For OOP, and my limited knowledge, I was thinking creating a class for each tab (each week) so I wrote the program like this. If there is a better set up, I am happy to learn. Thanks for the assistance. Here is the shorten version of the program.

import tkinter as tk
from tkinter import ttk

#upper tabs
upper_tabs = ["Final", "Requests", "Control"]
lower_tabs = ["Week 1", "Week 2"]
tabs2 = {} #upper
tabs = {} #lower

class Application(tk.Frame): #inherent from frame.
    def __init__(self, parent):
        tk.Frame.__init__(self, parent, bg="tan")
        self.parent = parent
        self.pack(fill=tk.BOTH, expand=1)
        self.Days= ["Monday", "Tuesday", "Wednesday", "Thursday",    
                    "Friday", "Saturday", "Sunday"]
        self.GUI()

    def GUI(self): #the function that runs all the GUI functions.
        self.create_lower_tabs()

####---------create grid_GUI---------------------####

    def create_lower_tabs(self):
        style1 = ttk.Style()
        style1.configure("down.TNotebook", tabposition = "sw")
        self.tabControl_lower = ttk.Notebook(self, width=1200,   
                                            height=550, padding = 0,  
                                            style = "down.TNotebook" )
        for name in lower_tabs:
            self.tab1=tk.Frame(self.tabControl_lower, bg='old lace')
            self.tabControl_lower.add(self.tab1, text=name, )
            tabs[name] = self.tab1 #add the widets to the dict.
            self.tabControl_lower.pack(fill=tk.BOTH, expand=1)

class Week_1(Application):
    def __init__(self, parent):
        Application.__init__(self, parent)
        week_1 = Week_1(Application)
        self.pack(fill=tk.BOTH, expand=1)
        self.GUI()

    def GUI(self): #the function that runs all the GUI functions.
        self.buttons("Week 1")

    def buttons(self, name):
        self.button = tk.Button(tabs[name], text="test button",          
                                bg="salmon",)
        self.button.pack()



def main():
    root = tk.Tk()
    root.title("class basic window")
    root.config(background="LightBlue4")
    app = Application(root)
    root.mainloop()

if __name__ == '__main__':
    main()
fishtang
  • 167
  • 3
  • 9
  • You never create a instance of `Week_2`. Second, indentation error at `Week_2.GUI`. Redesign to `class Application` holds **only** `notebook lower tabs` with Instances of `Week_1` and `Week_2` bound to `notbook tabs`. `class Week` hold all Week widgets. – stovfl Dec 04 '18 at 11:28
  • @stovfl thanks for your comments on reorganize the parent class. just to make it even simpler, I now modified the code to just show one button and still does not work. I don't know where is the problem and that's why I need your help. I created an instance, but maybe the placement of instance is not right? I did put the instance in between "def buttons()" and "def main()" and it says "TypeError: __init__() missing 1 required positional argument: 'parent'" Is it possible that you can point out exactly where i am wrong? thanks again. – fishtang Dec 06 '18 at 06:40
  • It's to broad for SO. Setup a [GitHub Gist](https://gist.github.com), I will comment there. – stovfl Dec 06 '18 at 10:04
  • @stovfl it's up on GitHub Gist. https://gist.github.com/Fishtang01/31206d1fddf5c7db318fd2dae9e3d8f8 thanks again. – fishtang Dec 06 '18 at 18:03

0 Answers0