RSS Forums RSS

Yet another pygame help thread

Please support our Python advertiser: Programming Forums
Thread Solved
Reply
Posts: 250
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 2
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz in Training

Yet another pygame help thread

  #1  
Dec 3rd, 2008
Im testing out blit() and i ran into this error:
  1. Traceback (most recent call last):
  2. File "/home/tom/Desktop/pygame/test/main.py", line 15, in <module>
  3. screen.blit('image.jpg', (10,10))
  4. TypeError: argument 1 must be pygame.Surface, not str
  5.  
  6. this is my code:
  7.  
  8. import pygame
  9. pygame.init()
  10. running = 1
  11. while running == 1:
  12. screen = pygame.display.set_mode((800, 600))
  13. event = pygame.event.poll()
  14. for event in pygame.event.get():
  15. if event.type == pygame.QUIT:
  16. running = 0
  17. image = pygame.image.load('image.jpg').convert()
  18. screen.blit('image.jpg', (10,10))
  19. screen.fill((0, 0, 0))
  20. pygame.display.flip()

any ideas?
Last edited by tomtetlaw : Dec 3rd, 2008 at 3:28 am.
AddThis Social Bookmark Button
Reply With Quote  
Posts: 770
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 139
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Yet another pygame help thread

  #2  
Dec 3rd, 2008
  1. screen.blit(image, (10,10))
I think..
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote  
Posts: 250
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 2
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz in Training

Re: Yet another pygame help thread

  #3  
Dec 4th, 2008
Nah, that didnt work, but it did get rid of the error, just dosnt show the pic on screen.
Reply With Quote  
Posts: 2,947
Reputation: vegaseat is a jewel in the rough vegaseat is a jewel in the rough vegaseat is a jewel in the rough 
Solved Threads: 254
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Yet another pygame help thread

  #4  
Dec 4th, 2008
Generally its done this way ...
  1. import pygame
  2.  
  3. # optional
  4. pygame.init()
  5.  
  6. # create the screen (or pygame window)
  7. screen = pygame.display.set_mode((800, 600))
  8.  
  9. # fill the screen black (default)
  10. screen.fill((0, 0, 0))
  11.  
  12. # pick an image you have (.bmp .jpg .png .gif)
  13. # if the image file is not in the working folder,
  14. # use the full pathname
  15. # convert() is optional for higher speed
  16. image = pygame.image.load('image.jpg').convert()
  17.  
  18. # draw image and position the image ulc at x=10, y=10
  19. screen.blit(image, (10,10))
  20.  
  21. # nothing gets displayed until one updates the screen
  22. pygame.display.flip()
  23.  
  24. # start event loop and wait until
  25. # the user clicks on the window corner x
  26. while True:
  27. for event in pygame.event.get():
  28. if event.type == pygame.QUIT:
  29. raise SystemExit
You had some indentation problems, and filled the screen black after drawing the image. Also, don't put the file loading into the event loop or it will keep loading and loading ...
May 'the Google' be with you!
Reply With Quote  
Posts: 250
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 2
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz in Training

Re: Yet another pygame help thread

  #5  
Dec 5th, 2008
THanks man, that solved it all XD.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the Python Forum
Views: 581 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:48 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC