I am working on a chess game. I have all the images I need stored in a folder: Chess/gui_pythonista/imgs/ and a file Chess/gui_pythonista/sprites.py. In the file, I want to load the images from the images folder to something that can be used by scene.image(). Here is the code in sprites.py:
import scene
import Image
import os
folder = 'imgs'
format = 'Chess set images {} {}.jpg'
files = [os.path.join(folder, format.format(color, type))
for type in ('pawn', 'rook', 'queen', 'king', 'bishop', 'knight')
for color in ('black', 'white')]
img_names = {}
for file in files:
name = os.path.split(file)[1]
im = Image.open(file).convert('RGBA')
im.show()
img = scene.load_pil_image(im)
img_names.update({name: img})
if __name__ == '__main__':
for key in img_names:
print key, img_names[key]
However, in the file Chess/gui_pythonista/screen_main.py file, where I from Chess.gui_pythonista.sprites import img_names, and use something like scene.image(img_names[piece_img]), all I get is a white box.
Would putting the code in sprites.py in the screen_main.py fix this?