2

So I've been trying to piece together something in Tkinter in Python 2.7 and I'm stuck somewhere.

I'm trying to get a fullscreen image to show up on my screen as a background, and put over several images, whom are transparent.

I've been told canvas is the 'only' way to go. So far, I have this:

# -*- coding: utf-8 -*-
#!/usr/bin/python
from Tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.attributes('-fullscreen', True)
root.configure(cursor='none')

frame = Frame(root)
frame.pack()

bg_image = ImageTk.PhotoImage(file='weather_bg.png')
canvas = Canvas(root, width=800, height=480, highlightthickness=0)
canvas.pack()
canvas.create_image(0, 0, image=bg_image, anchor='nw')

img = ImageTk.PhotoImage(file='cloud.png')
Label(canvas, image=img, borderwidth='0').place(x = 335, y = 80)

root.mainloop()

The image that I want with a transparency does show up on top of the background image, although with gray for transparency..

A quick HTML test showed red transparency in my PNG file:

<html>
  <body bgcolor="red">
    <img src="cloud.png">
  </body>
</html>

Help would be greatly appreciated!

user5740843
  • 1,540
  • 5
  • 22
  • 42
  • 2
    Your problem in fact, that your `cloud.png` is transparent relative to `Label`, when `Label` isn't transparent relative to `canvas` (*gray for transparency*). You need to [paste](https://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil) one image to another. – CommonSense Jul 11 '17 at 14:38
  • @CommonSense What if I want to make more than one image/canvas transparent relative to the background image? – user5740843 Jul 11 '17 at 15:39
  • there's no problem with that except, maybe, a performance. – CommonSense Jul 11 '17 at 15:57

0 Answers0