Sheldor
Sheldor

Reputation: 21

tkinter wm_grid() got an unexpected keyword argument 'row'

In line 11 I tried to use the grid(), but it keeps giving me "wm_grid() got an unexpected keyword argument 'row'" error Can anyone take a look at this?

import tkinter as tk


class MainPage(tk.Tk):

    def __init__(self, *args, **kwargs):

        tk.Tk.__init__(self, *args, **kwargs) 

        container = tk.Frame(self)
        container.pack(side="top", fill="both", expand=True)
        container.grid_rowconfigure(0, weight=1)
        container.grid_columnconfigure(0, weight=1)

        # pass frames as dictionaries
        self.frames = {}

        frame = StartPage(container, self)
        self.frames[StartPage] = frame
# problem here****************************************************
        frame.grid(row=1, column=1)
# problem here****************************************************          
        self.show_frame(StartPage)

    def show_frame(self, controller):
        frame = self.frames[controller]
        frame.tkraise()


class StartPage(tk.Tk):

    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text="StartPage")
        label.pack(pady=10, padx=10)

root = MainPage()
root.mainloop()

Upvotes: 0

Views: 3811

Answers (1)

Anand S Kumar
Anand S Kumar

Reputation: 90999

I guess the issue for you comes because you are subclassing StartPage from tk.Tk , you cannot use row/column keyword arguments for grid in that case.

But I believe that you really did not intend it to be a subclass of tk.Tk , since you seem to be trying to initialize tk.Frame inside it. I believe the fix in your case would be to inherit the class from tk.Frame instead as -

class StartPage(tk.Frame):

Upvotes: 2

Related Questions