Yet another pygame help thread

Thread Solved

Join Date: Sep 2008
Posts: 368
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Yet another pygame help thread

 
0
  #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 4:28 am.
...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,041
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 261
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Yet another pygame help thread

 
1
  #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 Quick reply to this message  
Join Date: Sep 2008
Posts: 368
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Yet another pygame help thread

 
0
  #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 Quick reply to this message  
Join Date: Oct 2004
Posts: 3,956
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Yet another pygame help thread

 
0
  #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 Quick reply to this message  
Join Date: Sep 2008
Posts: 368
Reputation: tomtetlaw is an unknown quantity at this point 
Solved Threads: 4
tomtetlaw's Avatar
tomtetlaw tomtetlaw is offline Offline
Posting Whiz

Re: Yet another pygame help thread

 
0
  #5
Dec 5th, 2008
THanks man, that solved it all XD.
...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC