I designed a form having an image as its background using a Canvas, then I want to put other widgets with transparent background over the Canvas. To do that I used root.wm_attributes('-transparentcolor', '#2a1863')
and then the widgets having that colour as background color assune a transparent background but I do not see, as I would expect, the canvas background image, instead I see what is on my LCD screen.
I modified my code to display a text on the canvas using canvas.create_text(text="Welcome!")
just to show what I want to have putting a Label over the Canvas. The problem is not limited only to Label widget.
Below there is the image as produced by my code:
Asked
Active
Viewed 832 times
1

Thingamabobs
- 7,274
- 5
- 21
- 54

Massimo Manca
- 385
- 1
- 2
- 15
-
`root.wm_attributes('-transparentcolor', '#2a1863')` sets a colorkey for the **windows** transparency. That's why you call it on the window. Anyway, you can have transparent pictures, even picture of text. Does this solve your question? – Thingamabobs Apr 19 '22 at 18:57
-
No, I want to have the same effect as Welcome! that is created by canvas.create_text() but using a Label. – Massimo Manca Apr 19 '22 at 19:25
-
Tkinter dosent offers an built in way to do so. I posted [an opportunity for MS-Windows](https://stackoverflow.com/a/70150296/13629335) that should also work with a Label. – Thingamabobs Apr 19 '22 at 20:32
-
For me your code for Windows does not work, hwnd in SetLayeredWindowAttributes() produces a wrong parameter error, hwnd = root.winfo_id() works but in this case all the window except the border becomes transparent – Massimo Manca Apr 19 '22 at 21:38
-
At the weekend I may find some time to take a look on the label. I'm surprised it dosent worked out. Please add your system information as well as the python, tkinter and win32 version. – Thingamabobs Apr 19 '22 at 21:52
-
My application has to work on Win7 to Win10 at leaast, better if it works on Win11. I am using Python 3.8.6 and tkinter embedded on it. – Massimo Manca Apr 25 '22 at 00:18