Skip to content
Advertisement

Python- Saving/Accessing file extension icons and using them in a Tkinter program

I’m currently trying to figure out how to create some code which will take the input of a file extension like ‘.png’ and return the icon associated with that filetype on the system.

I’m using python 2.7.6 and using Windows 8. I’ve been looking for code for this for hours to things close to it by saving images from .exe files but not finding the file extension in the registry and saving it.

I have found some code that works and allows me to save the file as a bmp which basically works by using wxpython’s icon to bitmap workings and saves the image as well. However, I would the code to simply not use wxpython since I’m using Tkinter to code the interface itself .

Here’s the code that currently works (adapted slightly) from http://ginstrom.com/scribbles/2007/08/31/file-list-with-icons-on-wxpython-windows/

JavaScript

Any help is greatly appreciated!

Advertisement

Answer

Inspired by IronManMark20’s answer. This version returns a PIL image so it doesn’t require the disc I/O of creating a temporary file. It also can get the different image sizes (see below) For more information, check this blog post.

JavaScript

Test Cases

Advertisement