'TypeError: __init__() takes from 1 to 2 positional arguments but 3 were given while working with GUI
So, I am trying to make some basic functionality for my GUI. But I keep running into the same error:
TypeError: init() takes from 1 to 2 positional arguments but 3 were given. In the line:
frame = F(container, self)
I searched the web for about an hour but couldn't find anything that worked. Any help would be appreciated.
class MyClass(Tk):
def __init__(self):
Tk.__init__(self)
container = ttk.Frame(self)
container.pack(side='top', fill='both', expand=True)
self.frames = {}
for F in (StartPage, LoginPage, FiltersPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(column=0, row=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, controller):
frame = self.frames[controller]
frame.tkraise()
F stands for one of the pages of the app, the code below shows an example of one of the pages.
class StartPage(ttk.Frame):
def __init__(self, parent, controller):
self.controller = controller
ttk.Frame.__init__(self, parent)
self.startMenu()
def startMenu(self):
heading = Label(self, text="My App", font=('Arial', 30))
heading.grid(column=0, row=0)
start_button = Button(self, text="Start", font='Arial 16', width=8, command=lambda: self.controller.show_frame(LoginPage))
start_button.grid(column=0, row=1)
exit_button = Button(self, text="Exit", font='Arial 16', width=8, command=self.controller.destroy)
exit_button.grid(column=1, row=1)
Solution 1:[1]
Turns out I was just way too tired when I got this error, I completely forgot to set up one of the other classes, which messed up the for loop. So lesson learned: don't try to fix stuff when you are tired.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Olle |
