This is graphics.py from the zelle book. The following code seemed to be working but when i added the parameters to the function def drawEye(win, centre, radius): i get an error when i try to execute it
Traceback (most recent call last):
File "C:\Documents and Settings\Compaq_Owner\Desktop\t.py", line 22, in <module>
drawEye()
TypeError: drawEye() takes exactly 3 arguments (0 given)
>>>

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawEye(win, centre, radius):
    w = 250
    h = 250
    win = GraphWin("One Spooky Eye", w, h)
    # center should be at 1/2 width and height
    centre = Point(w//2, h//2)
    drawCircle(win, centre, 40, "white")
    drawCircle(win, centre, 20, "blue")
    drawCircle(win, centre, 10, "black")
    # click mouse to go on
    win.getMouse() 
    win.close()

drawEye()

You can pull a few fixed things out of the drawEye() function and use parameters, but radius makes no sense since it changes within the function ...

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawEye(win, centre):
    drawCircle(win, centre, 40, "white")
    drawCircle(win, centre, 20, "blue")
    drawCircle(win, centre, 10, "black")
    # click mouse to go on
    win.getMouse() 
    win.close()

w = 250
h = 250
win = GraphWin("One Spooky Eye", w, h)
# center should be at 1/2 width and height
centre = Point(w//2, h//2)

drawEye(win, centre)

Remember if you put arguments/parameters in the function, you have to supply them as you call the function!

You can pull a few fixed things out of the drawEye() function and use parameters, but radius makes no sense since it changes within the function ...

from graphics import *

def drawCircle(win, centre, radius, colour):
    circle = Circle(centre, radius)
    circle.setFill(colour)
    circle.setWidth(2)
    circle.draw(win)

def drawEye(win, centre):
    drawCircle(win, centre, 40, "white")
    drawCircle(win, centre, 20, "blue")
    drawCircle(win, centre, 10, "black")
    # click mouse to go on
    win.getMouse() 
    win.close()

w = 250
h = 250
win = GraphWin("One Spooky Eye", w, h)
# center should be at 1/2 width and height
centre = Point(w//2, h//2)

drawEye(win, centre)

Remember if you put arguments/parameters in the function, you have to supply them as you call the function!

what about radius as a parameter for the second function? thts wht is causing the error when i try to add it in? and I still get an error when i close the graphics window for the above code

Traceback (most recent call last):
File "C:\Documents and Settings\Compaq_Owner\Desktop\t.py", line 23, in <module>
drawEye(win, centre)
File "C:\Documents and Settings\Compaq_Owner\Desktop\t.py", line 14, in drawEye
win.getMouse()
File "C:\Python26\lib\site-packages\graphics.py", line 327, in getMouse
if self.isClosed(): raise GraphicsError, "getMouse in closed window"
GraphicsError: getMouse in closed window

Strange, I tested the code and had no problems!

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.