Hello Everyone, and welcome to Tkinter, Part 5! This tutorial is short because we only talk about how to load a wide array of images and then to use those images on a toolbar. For this tutorial, you will need to download the 4 images provided as an attachment at the end of this tutorial. You may or may not need to download the PIL module (Python Imaging Library). For Windows, you can download it here: http://www.pythonwar...m/products/pil/ or on linux type:

$ sudo apt-get install python-imaging

Alright. Let's get started with the library imports:

from Tkinter import * // loads Tkinter
from PIL import Image, ImageTk

The Image class loads images and the ImageTk class makes them compatible (Without it, we would be restricted to GIFs). Next, We set up our GUI class:

I completely understand that having all of these images as separate variables is a hassle, but, unfortunately, at the time that this tutorial was written, there is a bug in PIL where, if a reference to that image is not made, then it gets destroyed by the garbage collector. However, you could always define another class, or a list, or some other datatype to help facilitate this. Next, all we did was added the image to the button using the image flag and setting them to the callback.

The next thing that I'm going to do is something that you've seen before, and that is to add a simple text box and scrollbar to the screen (just to make it look more complete; also in __init__):

Again, very simple. The PIL is a huge image library that is extraordinarily useful. From the link that I provided at the beginning is a link to documentation. I recommend downloading it and learning more about this library.

Here is the zip file (including source code, for those who didn't put it together correctly):Toolbars.zip(2.4K)Number of downloads: 754