0

Running into an issue trying to grid a framed object I created in a rudimentary paint program.

The instantiation code that gets the error is here:

from tkinter import *
from Menu import Menu

class Application(Frame):
    def __init__(self, master=None):
        Frame.__init__(self,master)
        self.grid()
        self.createWidgets()

    def createWidgets(self):
        #Imports each of the frames from the collection from the various widgets
        menu=Menu()
        menu.grid(row=0,column=0,columnspan=2)

app=Application()
app.master.title=('Sample Application')
app.mainloop()

The error I receive is related to the menu=Menu() operation and is:

TypeError: Menu() missing 1 required positional argument: 'Frame'

The Menu object is here:

from tkinter import *
import CommandStack

def Menu(Frame):
    def __init__(self, master=None):
        Frame.__init__(self,master)
        self.createWidgets()

    def createWidgets(self):
        self.new=Button(self,command=CommandStack.new())
        self.save=Button(self,command=CommandStack.save())
        self.save.grid(row=0,column=1)
        self.load=Button(self,command=CommandStack.load())
        self.load.grid(row=0,column=2)

My confusion is how that positional error occurs. When I give the menu a frame (self), the grid method instead I get this error:

AttributeError: 'NoneType' object has no attribute 'grid'

I feel liking I'm missing a key part of working with frames, but I'm not sure what. Suggestions?

1
  • 3
    Are you intending that Menu be a class or a function? You've defined it as a function (def) but implemented it like a class (__init__). Commented Apr 23, 2018 at 15:25

1 Answer 1

2

You seem to want Menu to be a class, and therefore defined it as such with the __init__ method. But you instead defined Menu to be a function, therefore all functions you stored inside are just defined as code that you would only use in the function. Change the def Menu to class Menu and it should be fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Youre welcome! Can you verify my answer while youre at it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.