pythontkinterbackgroundwidgettransparent

Tkinter text with transparent background


my only question is how to make a transparent text in tkinter : any type of widget with transparent background is a good answer. I need this for apply the text on a picture. Thanks for any type of answer


Solution

  • There are multiple ways of doing this, for example you could have an png image with text(do this via a photo editor), you can use a canvas and draw on that, or you can use a disabled button with an image background with text.

    Canvas:

    c = tk.Canvas(root)
    c.pack()
    c.create_image(x, y, img)
    c.create_text(x, y, "My Text")
    

    Button:

    img = PhotoImage(file="file.png")
    b = tk.Button(root, text="My Text", image=img, relief="FLAT", state="DISABLED")
    b.image = img
    b.pack()