I've got a Frame Object that creates all the GUI for my program, and I'm trying to call it in my main function and send it some arguments to use. However, I cant figure out where I need to add them into the object so that it will except them properly, I keep getting an error that says Im giving it more arguments than it can take.

This is the Frame object's constructor method:

class Application(Frame):

    def __init__(self, master):
        Frame.__init__(self, master)
        self.pack(expand = 1, fill = BOTH)

        #Creates the canvas to draw everything on
        self.window = Canvas(self, bg = "#00CD00", width = 1000, height = 625)

        #Imports all the card images into a 2d list
        self.import_cards()

        #Draws the window
        self.create_window()

and the section from my main code:

def __draw_window(player1, player2):
    root = Tk()
    root.title("WAR")
    dimensions = str(root.winfo_screenwidth()-100) + "x" + str(root.winfo_screenheight()-300)
    root.geometry(dimensions)
    root.resizable(0,0)
    app = Application(root, player1, player2)
    app.mainloop()

Recommended Answers

All 4 Replies

I do not know the TK library ( It is disturbing to me, that the application is a frame object, too), but syntactically:

class Application(Frame):

    def __init__(self, master,player1, player2):

should do the trick.

That was my first guess as well, but it didnt work.

Application is an object that is based off the Frame object. then you instantiate new Application objects

Could you paste or attach the code?
I will look at it tonight (europe time).

I keep getting an error that says Im giving it more arguments than it can take.

You are sending player1 and player2 to the class, but don't have arguments for them. If that doesn't answer your question, then post back.

class Application(Frame):

    def __init__(self, master, player1, player2):
        Frame.__init__(self, master)
        self.pack(expand = 1, fill = BOTH)
        print "this Frame is for", player1, player2
        ##
        ##   And generally you want to use this instance of Frame
        ##   outside of this class
        self.this_frame = Frame( master)
        ##   you can then pass app.this_frame to another function
        ##   from the __dtaw_window function

def __draw_window(player1, player2):
    root = Tk()
    root.title("WAR")
    dimensions = str(root.winfo_screenwidth()-100) + "x" + str(root.winfo_screenheight()-300)
    root.geometry(dimensions)
    root.resizable(0,0)
    app = Application(root, player1, player2)
    app.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.