Putting images in a Tkinter
How can I place an image in a Tkinter GUI using the python standard library?开发者_开发知识库
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.
You can Built-In the images on the code encoding it on Base64
精彩评论