2

How can I add a transparent tkinter image in Python 3.3.2? I have tried using .gifs however the transparent parts become white.

Example:

from tkinter import *
Foo = PhotoImage(file=Bar)
image = Label(root, image=Foo)
image.pack()

It can find the image and everything however all transparent parts of the gif are white...

(They are transparent when opened in Photoshop or any other image viewing/editing program)

Thank you for any help! :D

(Psst. It doesn't have to be just gifs however if I try to use anything else; I get an error saying that it cannot read the data in my image.)

[Edit] Here is the traceback when I attempt to use the above code to open a .png with transparency.

  File "C:\Python33\lib\tkinter\__init__.py", line 3362, in __init__
    self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: couldn't recognize data in image file ".\Stuff\Foo.png"
Logic
  • 21
  • 3
  • To get a hint, you should maybe take a look at [this](http://stackoverflow.com/questions/765736/using-pil-to-make-all-white-pixels-transparent) and [this](http://stackoverflow.com/questions/3270209/how-do-i-make-tkinter-support-png-transparency) question – albert Jun 08 '15 at 16:38
  • The traceback is because of an invalid fileformat. To use png files you have to use PIL as shown [here](http://effbot.org/tkinterbook/photoimage.htm). However, I tried this with the hints of my last comment and could not achieve a satisfying result. – albert Jun 08 '15 at 17:26
  • I don't think PIL works with Python v3.3.2... :/ – Logic Jun 08 '15 at 18:08
  • I am using PIL with Python 3.4.3 and at least it is working with non-transparent images. – albert Jun 08 '15 at 18:09
  • Have you tried PIL with non-transparent images? – albert Jun 08 '15 at 18:30

0 Answers0