Josh
Josh

Reputation: 664

Python GUI toolkits that support text widget transparency or text widget with canvas background?

I am trying to write a program that displays a scrollable text widget over a striped background. The width of the stripes, the spacing between stripes, and the color of the stripes can be set by the user.

Here is a quick and dirty example of what I'm imagining:

Example

(It might seem like an ugly and pointless program, but it would be useful as a therapy tool for certain kinds of eye problems)

My original idea was to draw the stripes as rectangles on a canvas widget. Then I planned on overlaying the canvas with a text widget with a transparent background.

Right now, I am using Tkinter. But it appears that the text widget in Tkinter doesn't support transparency or using a canvas as a background. It appears that only a solid color can be used as a background.

What GUI toolkits are available for Python that would support the use of text widget background transparency / or a text widget that uses a canvas as a background?

Upvotes: 0

Views: 3339

Answers (2)

Steven Rumbalski
Steven Rumbalski

Reputation: 45552

If you are willing to use Tkinter, here is a short example using the canvas widget.

import Tkinter as tk

class Example(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        canvas = tk.Canvas(self, width=800, height=500)
        canvas.pack(side="top", fill="both", expand=True)
        for i in range(0, 800, 40):
            i+= 40
            fill = "yellow" if (i / 40) % 2 == 0 else "green"
            canvas.create_rectangle(i, 0, i+20, 500, fill=fill, outline="")
        canvas_id = canvas.create_text(10, 10, anchor="nw")
        canvas.itemconfig(canvas_id, text="this is the text "*300, width=780)
        canvas.itemconfig(canvas_id, font=("courier", 12))
        canvas.insert(canvas_id, 12, "new ")

if __name__ == "__main__":
    root = tk.Tk()
    Example(root).pack(side="top", fill="both", expand=True)
    root.mainloop()

Here is what it looks like:

screenshot of working example

Adding scrolling is left as an exercise for the reader.

Upvotes: 1

Serial
Serial

Reputation: 8043

Take a look at WXpython

here is an example of a transparent top-level window

Transparent Frames

WX is the only GUI library that i think could do this tkinter is good for more basic GUI's while WX is much more flexible

here are a few more examples of using transparency with WX

Transparent StaticText

Transparent Panel

I hope this helps you out!

Upvotes: 1

Related Questions