Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

Harry Court
Harry Court
3,645 Points

Python: function takes at most 4 arguments (5 given)

Hello there! I'm having a slight issue with my code. I have made a program where it can draw things onto a pygame canvas. However, I am getting the error (Stated in the title) and I have no clue how to fix it.

class drawing:
    def __init__(self):
        # Rect. Dimensions
        self.dimensionWidth = 0
        self.dimensionLength = 0

        # Circle Dimensions
        self.dimensionRadius = 0

    def drawRect(self):
        pygame.draw.rect(screen, (0,0,0), (250,250), self.dimensionWidth, self.dimensionRadius)
        pygame.display.update()

    def drawCircle(self):
        pygame.draw.circle(screen, (0,0,0), (250,250), self.dimensionRadius, self.dimensionRadius)


# Rectangle Creation Window
def rectCreationWindow():

    drawingClass = drawing()

    # Create the window.
    objWindow = Tk()
    objWindow.wm_title("Rect. Creation Window")
    objWindow.geometry("200x75")

    # Width
    widthEntry = Entry(objWindow)
    widthEntry.pack()
    widthEntry.focus_set()

    # Length
    lengthEntry = Entry(objWindow)
    lengthEntry.pack()
    lengthEntry.focus_set()

    drawing.dimensionWidth = widthEntry.get()
    drawing.dimensionLength = lengthEntry.get()

    createObjButton = tk.Button(objWindow, text ='Create Object', command=drawingClass.drawRect)
    pygame.display.update()
    createObjButton.pack()

    objWindow.mainloop()


def circleCreationWindow():

    drawingClass = drawing()

    # Create the window.
    objWindow = Tk()
    objWindow.wm_title("Circle Creation Window")
    objWindow.geometry("200x75")

    # Radius
    radiusEntry = Entry(objWindow)
    radiusEntry.pack()
    radiusEntry.focus_set()

    drawing.dimensionRadius = radiusEntry.get()

    createObjButton = tk.Button(objWindow, text ='Create Circle', command=drawingClass.drawCircle)
    pygame.display.update()
    createObjButton.pack()

    objWindow.mainloop()

1 Answer

Steven Parker
Steven Parker
216,136 Points

I'm not a "pygame" user, but when I looked up the documentation for pygame.draw.rect(), it says it takes 4 arguments:

rect(Surface, color, Rect, width=0)

But this code is passing it 5:

    pygame.draw.rect(screen, (0,0,0), (250,250), self.dimensionWidth, self.dimensionRadius)

I'm guessing rectangles probably don't have radiuses.