I created a function that creates smiley faces. I want to print more than 1 (with different size and location) on 1 window. How do I do it? Here is the code:

from graphics import *

def main():
    print drawface(Point(40, 40), 20, GraphWin)
    print drawface(Point(90, 90), 30, GraphWin)
    print drawface(Point(130, 160), 10, GraphWin)

def drawface(center, size, win):
    win = GraphWin()
    win.setBackground('white')
    
    center = Circle(center, size)
    center.draw(win)
    
    Point1 = center.getCenter()
    Point2 = size * .20
    Point3 = size * .30
    Point4 = size * .40
    Point5 = size * .25
    
    lefteye = Circle(Point1, Point2)
    lefteye.move(-Point3, -Point2)
    lefteye.draw(win)
    
    righteye = Circle(Point1, Point2)
    righteye.move(Point3, -Point2)
    righteye.draw(win)
    
    mouth = Circle(Point1, Point3)
    mouth.move(0, Point4)
    mouth.draw(win)
    
    mouth2 = Circle(Point1, Point3)
    mouth2.setFill('white')
    mouth2.setOutline('white')
    mouth2.move(0, Point5)
    mouth2.draw(win)

main()

If you walk through your code carefully, you'll see that the drawface() function does *way* too much. As a result, it clobbers any old faces that might be on the screen. The solution is to move the initialization out of the drawface() function, and then let drawface() do one single thing: draw a face.

Hope that helps; I've left out some of the details so that you can get the benefit of the debugging experience.

Jeff

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.