Being newer to Python, I am not sure how to pass my configuration data to a class, which inherits a Frame.
This read/sets configuration data
class clsConfig:
# init method/constructor
def __init__(self):
path = str(sys.path[0])
self.srcPath = path + "\\"
self.imagePath = self.srcPath + "Images" + "\\"
................
This class has configuration data, creates a notebook/tab calling my inherited class
class maingui:
def __init__(self):
# Set Config Values
config = clsConfig()
config.getConfiguration()
print("Config-Path: "+ config.srcPath)
# root
self.root = Tk() #Makes the window
self.root.wm_title("My tab")
# tab control - Main Control
self.tabMain = ttk.Notebook(self.root)
# *** I WANT TO PASS config DATA HERE ***
tabWeather = clsWeatherTab(self.tabMain)
self.tabMain.add(tabWeather,text="Weather")
This class is where I want to have available the config class data
class clsWeatherTab(Frame):
def __init__(self,name,*args,**kwargs):
Frame.__init__(self,*args,**kwargs)
self.label = Label(self, text="Hi This is Tab1-seperated")
self.label.grid(row=1,column=0,padx=10,pady=10)
self.name = name
# *** HERE I WANT TO USE PASSED config DATA ***
print("Config-Path: "+ config.srcPath)
Any guidance would be great.
thank you,
Dean
>Solution :
All you have to do is pass the config structure to the constructor for the tag frame:
class maingui:
def __init__(self):
# Set Config Values
config = clsConfig()
config.getConfiguration()
...
tabWeather = clsWeatherTab(self.tabMain, config)
self.tabMain.add(tabWeather,text="Weather")
...
class clsWeatherTab(Frame):
def __init__(self,name,config,*args,**kwargs):
Frame.__init__(self,*args,**kwargs)
self.config = config
self.label = Label(self, text="Hi This is Tab1-seperated")
self.label.grid(row=1,column=0,padx=10,pady=10)
self.name = name
print("Config-Path: "+ config.srcPath)