I want to store .jpg
images from a folder in an array, and than use them to add it to a buttons in my frame of Python.
I am using tkinter and PIL library in Python 3.4.3 .I am using windows 8.1 os I want to load the image for a folder with few lines of code and I also element border of the grid to show them like a single image
Below is some code to get you started.
To simplify testing I wrote a small program that uses PIL to generate colored squares and saves them to a folder. I tested these programs using Python 2.6.6 on Linux. They should work on Python 3, (assuming Tkinter & PIL are installed properly on your system) but you will need to change
import Tkinter as tk
toimport tkinter as tk
in tk_frame_grid.py.This program generates 30 colored squares, saving them to the 'squares' folder in the current directory. You need to create 'squares' before running the program.
PIL_2colorsquares.py
This program first fills a list with PIL images, using image files from a named directory; these images can be in any file format that PIL can read. It then creates a Tkinter window containing a Frame that holds a grid of Buttons using the images. There is no error checking, so don't put non-image files into the 'squares' folder.
You need to specify the grid dimensions. If there aren't enough images to fill the grid you will get a
StopIteration
error.tk_frame_grid.py