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:
- It only accepts GIFs. (Example code for using PIL to convert to GIF while loading)
- 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
2010-09-13 08:56:47
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
2010-09-15 02:29:41