Suppose I have 2 files, frontend.py for displaying a GUI and backend.py for database functions. I am having an issue inheriting the database class using super(). from #backend2.py in the managerPage class in #frontend.py
I have the error:
frame = F(container, self) TypeError: init() missing 2 required positional arguments: 'cn' and 'cur'
I believe this has to do with init in the tk.Frame class which i have also inherited in the managerPage class. I believe the selfService class (which I have renamed for my own sake) is credited to user @BryanOakley. Could someone please help me successfully utilise super().
frontend.py.
import backend2
class selfService(tk.Tk, Toplevel):
def __init__(self, *args, **kwargs):
#Toplevel.__init__(self)
self.employeeWindow = None
tk.Tk.__init__(self, *args, **kwargs)
self.container = tk.Frame(self)
self.container.pack(side="top", fill="both",
expand = True)
self.container.grid_rowconfigure(0,
weight=1)
self.container.grid_columnconfigure(0,
weight=1)
self.frames = {}
selfService.restart = False
for F in (StartPage, PageOne, PageTwo):
self.frame = F(self.container, self)
self.frames[F] = self.frame
self.frame.grid(row=0, column=0,
sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
self.frame = self.frames[cont]
self.frame.tkraise()
class managerPage(tk.Frame,
validation.account_validation,backend2.Database):
def __init__(self, parent, controller, cn, cur):
tk.Frame.__init__(self,parent)
super().__init__(cn, cur)
print(self.cn)
backend2.py
class Database():
def __init__(self):
self.config = {
'user': 'root',
'password': 'root',
'host': 'localhost',
'database': 'myDatabase'}
self.cn =
mysql.connector.connect(**self.config)
self.cur = self.cn.cursor()