2

I made a custom image viewing program in python since I couldn't find one that worked how I wanted it to, and I know it at least USED to work with transparent gifs but now it doesn't. The effects seem to vary from gif to gif to gif but it always is an issue with the transparency. Doing some testing with .save I found that the PIL image is completely fine and I can export it as a png with absolutely no issues and perfect transparency. With that said, despite making the program I never really learned Tkinter since I just didn't need to use it beyond simple canvas clearing and updating, so I have no clue how to test beyond PIL. I believe the issue should be in these lines :

image = ImageTk.PhotoImage(GifFrameSized) #GifFrameSized is the resized GIF
imagesprite = canvas.create_image(show.w/2,show.h/2,image=image) #w and h are the width and height of the monitor
root.update_idletasks()
root.update()
canvas.pack()

I genuinely have no idea how the issue could be coming from any of these but I was able to use PIL to save a png of the frame in the line immediately above "image = ImageTk.PhotoImage(GifFrameSized)" and it looked fine so I have to imagine its somewhere in those lines.

  • 1
    You refering about an issue you never explained to us and havent given the code to reproduce it, nor you have showed exampels in your question. How is this question solvable at this state? Please review your question and add information that is needed to solve the question. – Thingamabobs Dec 29 '21 at 14:53
  • I literally can't explain it because as I said it varies from gif to gif depending on how they are encoded. I gave the code segment which is causing the issue, and every sinlge gif with transparency I have tested has had an issue. – TenDaysTillDallas Dec 29 '21 at 15:25
  • 1
    A look into my magic glass ball tells me you overlay your pictures with new ones and dont update the images. Also see [When should I use root.update() in tkInter for python](https://stackoverflow.com/questions/66781579/when-should-i-use-root-update-in-tkinter-for-python/66781785#66781785) – Thingamabobs Dec 29 '21 at 15:54
  • 1
    seems like an issue with the gif then, just because you can export it as png doesn't mean that it is transparent or the issue above – Matiiss Dec 29 '21 at 16:50
  • Try to convert the mode of the GIF image to "RGBA" using `GifFrameSized = GifFrameSized.convert("RGBA")`. – acw1668 Dec 30 '21 at 07:56
  • @acw1668 I tried adding that and it didn't seem to have an effect – TenDaysTillDallas Jan 08 '22 at 01:16
  • @Matiiss the gif is transparent, the png I export has normal transparency and I can open the gif in another image viewer such as window's build in "photos" and it displays fine. (I will say I do think the gif has something to do with it, when I try different gifs the transparency behaves differently for each one, like the bug in my code somewhere is failing a different way based on how they were each encoded but no matter how they are made it always breaks the transparency in some way) – TenDaysTillDallas Jan 08 '22 at 01:17
  • @Thingamabobs Quite possibly since I don't use tkinter, is there a reason that would cause transparency to be really strangely bugged? How would I go about just updating the images? I won't lie I do not understand tkinter at all so I've kind of just been running with what I found and it had worked perfectly fine until now. The link you sent did say something along the lines that if you use root.update your code might not work going forward so that sounds about right but I tried removing all uses of root.update and the image still displays fine, windows says its not responding though. – TenDaysTillDallas Jan 08 '22 at 01:18

0 Answers0