Python GUI工具包支持文本窗口小部件透明度或文本小部件与画布背景? [英] Python GUI toolkits that support text widget transparency or text widget with canvas background?

查看:799
本文介绍了Python GUI工具包支持文本窗口小部件透明度或文本小部件与画布背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个程序,在条纹背景上显示可滚动的文本小部件。条纹的宽度,条纹之间的间距和条纹的颜色可以由用户设置。

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.

这是一个快速和脏的例子, m想象:

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

(这可能看起来像一个丑陋的无意义的程序,但它将作为治疗工具用于某些类型的眼睛问题)

(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.

现在,我使用Tkinter。但是似乎Tkinter中的文本小部件不支持透明度或使用画布作为背景。似乎只有纯色可以用作背景。

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.

什么GUI工具包可用于Python,将支持使用文本小部件背景透明度或文本

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?

推荐答案

如果你愿意使用Tkinter,这里是一个简单的例子使用canvas

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()

以下是它的样子:

添加滚动作为练习留给读者。

Adding scrolling is left as an exercise for the reader.

这篇关于Python GUI工具包支持文本窗口小部件透明度或文本小部件与画布背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆