'Tkinter problem: __init__() takes 2 positional arguments but 3 were given
wish to get some guidance here. Initially when there is only 2 frame, StartPage and SplitTraining, the GUI works well. However, when I added the deepLearning class, it started to have t he problem of TypeError: init() takes 2 positional arguments but 3 were given
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args,**kwargs)
self.container = tk.Frame(self)
self.container.pack()
self.frames={}
for F in (StartPage, dataSplit, deepLearning):
frame = F(self.container, self)
self.frames[F]=frame
frame.configure(width=600, height=900)
frame.grid(row=0, column=0)
self.show_frame(StartPage)
def show_frame(self, controller):
frame=self.frames[controller]
frame.tkraise()
This is the class of deepLearning
class deepLearning(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self,parent)
pb1 = Progressbar(self, orient=HORIZONTAL, length=600)
pb1.pack(expand=True)
b1 = Button(self, text="Choose Folder",font=('Times_New_Roman',16), command=lambda:[inputFilesDir(),step()], fg="white", bg="black")
b1.pack()
Solution 1:[1]
The structure of your code requires that each page accepts the same two parameters: parent and controller. Since you're using this class like the other pages then it needs to accept the same parameters even if you don't use them.
class deepLearning(tk.Frame):
def __init__(self, parent, controller):
# ^^^^^^^^^^^^
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 | Bryan Oakley |
