Printing in one window

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2007
Posts: 6
Reputation: MakingMoney is an unknown quantity at this point 
Solved Threads: 0
MakingMoney MakingMoney is offline Offline
Newbie Poster

Printing in one window

 
0
  #1
Oct 15th, 2007
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:

  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()
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Printing in one window

 
0
  #2
Oct 15th, 2007
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC