I need to make my tkinter rectangles transparent. Does anyone know how to do that?
I have tried to specify alpha=".5", opacity=".5"
, and I have tried to add two more digits in the end of the color code: fill="#ff000066"
. None of these things seem to work, I can't find the right syntax.
import tkinter
root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=800, height=600)
canvas.pack()
canvas.create_rectangle(50, 50, 100, 100, fill="#ff0000", alpha=0.5)
root.mainloop()
This code gives me this message: _tkinter.TclError: unknown option "-alpha"
, so this is obviously not the right way to do it.
#rgb
,#rgba
,#rrggbb
, and#rrggbbaa
. What happens when you tryfill="#ff000080"
? (I'm pretty sure this is valid for HTML/CSS, not sure for tk).tkinter
doesn't support the transparency of items on aCanvas
. There are ways to make an entire top-level window transparent, but there's nothing to control it for individual widgets below that level (includingCanvas
objects).stipple='gray50'
, but it is not true transparency.