tags:

views:

34

answers:

2

How can I place an image in a Tkinter GUI using the python standard library?

+2  A: 

I don't normally use Tkinter, but I'll take a shot at answering. According to Google, loading images in Tkinter has two main gotchas:

  1. It only accepts GIFs. (Example code for using PIL to convert to GIF while loading)
  2. You have to manually keep a reference to images due to an inability to refcount them. (solution) (explanation)

The example code for loading non-GIF images should also work perfectly well as an example of the basic procedure for displaying images in Tkinter GUIs.

If you'd prefer a more practical example, PySol is a suite of solitaire games written with Tkinter and PySolFC, its successor, demonstrates the same usage adapted to the new python-ttk Tkinter API which Python 2.7 added.

ssokolow
A: 

You can Built-In the images on the code encoding it on Base64

juancarlospaco
Do tell, this sounds interesting. If I understand correctly the image will be built into the code, right? So it wouldn't depend on any external files.
Anteater7171