Search code examples
python-3.xtkinterspritealpha-transparency

Tkinter contents of both widgets visible when overlapping


So, I am trying to make a video game in Tkinter (no, I don't want to use PyGame), but I have ran into a bit of a problem.

I have realized that sometimes you may want to have two widgets overlap (e.g. sprite on top of background) but have the contents of both widgets to be visible. For example, I might have a sprite with transparent sections.

How do I set the "background" option of a widget so that there is no visible background?

Note: "you can't do this" answers are acceptable.


Solution

  • This is not really posible in Tkinter. But you can set the transparency of the whole window with root.attributes('-alpha', 0.5)

    For windows, you can do root.attributes("-transparentcolor", "red"), but again it will be applied to the whole window, not just the single widget.