python - error when using pygame.image.load() -


When I try to load an image in another folder ...

pygame. Error: Sprites / testtile.png can not be opened

I can properly load .png files if they are in the same directory, but once they are in another folder, then this error Meets.

P> I know that Python can also be used in other folders, because I can not find any error in importing API files.

When I try pygame.image.get_extended it gives 0 but loading.PNG files do not give me any trouble from the same directory, so I do not think this is the reason.

I am running Pychem on the way, and I feel like always, with this IDE, I do not even think that it is a pajama issue. There is no clue at this point.

folder structure:

script / graphics driver.py

sprites / testtile.png

driver, access to testile.png file Trying

The directory with the graphics driver is the sprites directory. Py? You can run some problems with PyGame Image Loader. It looks for files in the same directory, such as PyGame was initialized. Point it to the full path of your file using 'os.path.join'.

I usually write my small image loader around it, though it provides slightly more flexibility for the process. Something that will return the image and the text:

  def load_image (name, colorkey = none): "" "Loads an image and converts it into pixels." Foundname "fullname = os. Try path.join ('data', name): image = pygame.image.load (fullname) except for pygame.error, Message: Print 'image can not be loaded:', name system accelerated, message image = image Convert () #CorKarki has made the top left pixel color: if the caller does not have any: if Korkky-1 is: colorkey = image.get_at ((0,0)) image.set_colorkey (colorkey, RLEACCEL) image back, I Mage.get_rect ()   

Hope this will help.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

java - Reaching JTextField in a DocumentListener -

c# - Add Image in a stackpanel based on textbox input -