1

I did some research about opacity but I didn't find anything about the lines. I found some topics about the window or a rectangle only.

I would like to know if it is possible to have on Tkinter colored lines with a certain opacity that can be adjusted.

dashboard.create_line(init_x,init_y,event.x,event.y,width=pen_width,fill=pen_color,capstyle=ROUND,smooth=True,tag="line "+str(selectLine)
FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28
Stack Realtek
  • 87
  • 1
  • 6
  • 1
    Does this answer your question? [How to make a tkinter canvas rectangle transparent?](https://stackoverflow.com/questions/54637795/how-to-make-a-tkinter-canvas-rectangle-transparent) – FLAK-ZOSO Apr 23 '22 at 12:44
  • No because as I said in the question I had already found this for the rectangle and the window except that it does not apply to the line – Stack Realtek Apr 23 '22 at 14:24

1 Answers1

0

tkinter doesn't support transparent lines is the shortest answer.

Alternate solution

If your canvas background color is static, you can use this trick.

This is a pure red #FF0000 line with 0.5 alpha on a pure white #FFFFFF canvas in an external image editing tool. I used a higher line width so that it will be more visible. enter image description here

You can now use a color picker to copy this color (make sure it's RRGGBB) enter image description here

Now you can use this color as a fill for the line in your tkinter canvas. Using a polygon for better visiblity:

cv.create_polygon(10, 10, 500, 10, 500, 50, 10, 50, fill="#ff7f7f")

The result will look as following:

enter image description here

Notes

  • This answer assumes the canvas background to be static.
  • This is not really an efficient solution for this question.
Billy
  • 1,157
  • 1
  • 9
  • 18
  • It's a pity because it is supported with the rectangle or for the window though. Personally I create a paint app and I would have liked to be able to modify the opacity of each colored line drawn on the canvas. – Stack Realtek Apr 23 '22 at 14:21
  • Transparent rectangles are also not possible. The one question linked above shows adding an image of rectangle which is transparent. If you are aiming for a paint app, use some other framework, tkinter may not be the best option suited to that. – Billy Apr 23 '22 at 14:34
  • What do you recommend? I'm making a game that will be played online where one of the players draws and the others have to guess. Which frameworks would be suitable for me in this case? – Stack Realtek Apr 23 '22 at 14:36