944,098 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1299
  • Python RSS
Oct 15th, 2007
0

Printing in one window

Expand Post »
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:

Python Syntax (Toggle Plain Text)
  1. from graphics import *
  2.  
  3. def main():
  4. print drawface(Point(40, 40), 20, GraphWin)
  5. print drawface(Point(90, 90), 30, GraphWin)
  6. print drawface(Point(130, 160), 10, GraphWin)
  7.  
  8. def drawface(center, size, win):
  9. win = GraphWin()
  10. win.setBackground('white')
  11.  
  12. center = Circle(center, size)
  13. center.draw(win)
  14.  
  15. Point1 = center.getCenter()
  16. Point2 = size * .20
  17. Point3 = size * .30
  18. Point4 = size * .40
  19. Point5 = size * .25
  20.  
  21. lefteye = Circle(Point1, Point2)
  22. lefteye.move(-Point3, -Point2)
  23. lefteye.draw(win)
  24.  
  25. righteye = Circle(Point1, Point2)
  26. righteye.move(Point3, -Point2)
  27. righteye.draw(win)
  28.  
  29. mouth = Circle(Point1, Point3)
  30. mouth.move(0, Point4)
  31. mouth.draw(win)
  32.  
  33. mouth2 = Circle(Point1, Point3)
  34. mouth2.setFill('white')
  35. mouth2.setOutline('white')
  36. mouth2.move(0, Point5)
  37. mouth2.draw(win)
  38.  
  39. main()
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MakingMoney is offline Offline
6 posts
since Sep 2007
Oct 15th, 2007
0

Re: Printing in one window

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
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Style issue ... def main()
Next Thread in Python Forum Timeline: wxPython DateTime problems





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC