Using GIF images in Python GUI scripts

Using GIF images in Python GUI scripts

ironman_explosion

Knocked My Socks Off!


My coworkers and I attended our first JAMF Nation conference this past October. The last session I attended on the first day knocked my socks off. Bryson Tyrrell of JAMF showed off an iPhone ordering script he wrote in Python and Tk. I’ve written some Tk, but it was a long time ago and I remember it being an uncomfortable experience. It seems a lot has changed. His script included an image that would dynamically change based on user interaction. It was so cool I knew I needed to make use of this technique as soon as I could.

The script I’m currently working on will be used to populate inventory data in our Casper management system, collating data from LDAP, MySQL and the JSS. Being able to include images takes the look-and-feel to another level. Showing the user what the appropriate asset tag looks like should increase the likelihood that the correct data will be input.

Screen Shot 2016-02-25 at 6.45.36 PM

Encoding an Image


Here is a simple script that will properly encode a GIF image to be included in a script:

The following image of Swoop is shown encoded below.

swoop

Using your Image


Here is a simple Tk script that will display our encoded image:

Here’s what the running script looks like:

Screen Shot 2016-02-25 at 8.08.22 PM

Other Options


I’m currently using TKinter/ttk as they are included in the stock Python install, but support is limited to GIF and PGM/PPM formats. However, there are a couple other options when it comes to displaying images in python. The Python Imaging Library (PIL) offered many more image formats, but development appears to have ceased. Pillow forked PIL and is under active development.

 

Tags:
, , , , ,
2 Comments
  • Bryson3Gps
    Posted at 00:15h, 27 February Reply

    Great sample write-up! I’m glad you rolled the idea of the session to borrow the code and concepts to apply to your own solutions. I’ve been using Pillow for an internal Gravatar-like service I’ve been writing for us and it’s powerful library.

    • Todd McDaniel
      Posted at 18:26h, 29 February Reply

      Thank you for your kind words, and your very inspiring presentation!

Leave a Reply