| | |
Yet another pygame help thread
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
Im testing out blit() and i ran into this error:
any ideas?
python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "/home/tom/Desktop/pygame/test/main.py", line 15, in <module> screen.blit('image.jpg', (10,10)) TypeError: argument 1 must be pygame.Surface, not str this is my code: import pygame pygame.init() running = 1 while running == 1: screen = pygame.display.set_mode((800, 600)) event = pygame.event.poll() for event in pygame.event.get(): if event.type == pygame.QUIT: running = 0 image = pygame.image.load('image.jpg').convert() screen.blit('image.jpg', (10,10)) screen.fill((0, 0, 0)) pygame.display.flip()
any ideas?
Last edited by tomtetlaw; Dec 3rd, 2008 at 4:28 am.
...
Generally its done this way ...
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 ...
python Syntax (Toggle Plain Text)
import pygame # optional pygame.init() # create the screen (or pygame window) screen = pygame.display.set_mode((800, 600)) # fill the screen black (default) screen.fill((0, 0, 0)) # pick an image you have (.bmp .jpg .png .gif) # if the image file is not in the working folder, # use the full pathname # convert() is optional for higher speed image = pygame.image.load('image.jpg').convert() # draw image and position the image ulc at x=10, y=10 screen.blit(image, (10,10)) # nothing gets displayed until one updates the screen pygame.display.flip() # start event loop and wait until # the user clicks on the window corner x while True: for event in pygame.event.get(): if event.type == pygame.QUIT: raise SystemExit
May 'the Google' be with you!
![]() |
Similar Threads
- Drawing a moving circle with Python Tkinter + good GUI tutorial (Python)
- Help finding C++ Projects (C++)
Other Threads in the Python Forum
- Previous Thread: PyGTK tray menu has annoying scroll arrows
- Next Thread: Mario clone
Views: 712 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Python
abrupt apache application argv beginner binary book calculator change cipher code command converter dictionaries dictionary dynamic event examples excel file float format ftp function google gui hints homework import inches input java keyboard launcher line linux list lists loop maze microphone mouse movingimageswithpygame newb number numbers obexftp output parsing path permissions phonebook plugin port prime program programming projects py2exe pygame pyqt python random recursion recursive refresh remote scrolledtext search session signal simple ssh string strings strip table terminal text thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 valueerror variable verify vigenere windows wordgame wxpython xlwt






