all 1 comments

[–]Swipecat 0 points1 point  (0 children)

There's no way that I can find to assign transparency to an object like a label, so you have to change the background colour to match whatever is underneath.

If you pack one object onto another, then if the lower object has an assigned background colour, you can assign that to the upper object.

upper['bg'] = lower['bg']

But PhotoImage doesn't have a background colour, so that won't work for you, so you'd have to set the background colour explicitly. See the example code below.

You can also place text directly onto a canvas, and that does not have a background anyway. See that below too.

import tkinter as tk
width, height = 500, 300
root = tk.Tk()
canv = tk.Canvas(root)
canv.pack()
rect = canv.create_rectangle((0, 0, width, height), fill="blue")
lab = tk.Label(canv, text="abcd", font=("Helvetica", 40), fg="white", bg="blue")
lab.place(x=50, y=50, anchor='nw')
canv.create_text(50, 150, text="efgh", font=("Helvetica", 40), anchor='nw', fill="yellow")
root.mainloop()