SFML community forums

Bindings - other languages => Python => Topic started by: magikmw on October 29, 2012, 09:43:49 pm

Title: Problem with Image.load_from_file()
Post by: magikmw on October 29, 2012, 09:43:49 pm
I'm having problems with loading a png into an Image object.
The same method works fine with Texture.

Code follows, first my call, and then the error.

# Load the icon file
icon = Image.load_from_file('game/pngs/icon.png')
window.set_icon(16,16,icon.get_pixels())

Traceback (most recent call last):
  File "/usr/lib/python3.3/runpy.py", line 160, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python3.3/runpy.py", line 73, in _run_code
    exec(code, run_globals)
  File "game/__main__.py", line 302, in <module>
    main()
  File "game/__main__.py", line 281, in main
    icon = Image.load_from_file('game/pngs/icon.png')
  File "sfml.pyx", line 1870, in sfml.Image.load_from_file (src/sfml.cpp:23910)
TypeError: expected bytes, str found
 

I'm thinking it's an API error or maybe I'm doing something wrong?

Edit:
Oh, and I'm using SFML 2.0 RC1, pySFML build from tar on github, and Python3.3
Title: Re: Problem with Image.load_from_file()
Post by: bastien on December 02, 2012, 11:31:35 pm
I fixed it on the master branch. Until you can get an updated build, you can use the b prefix to pass a bytes string:

Code: [Select]
icon = Image.load_from_file(b'game/pngs/icon.png')