【问题标题】:How to set the transparency of the tkinter frame?如何设置 tkinter 框架的透明度?
【发布时间】:2021-04-11 04:16:19
【问题描述】:

Python 2.7 版

代码:

from Tkinter import *

root = Tk();
root.geometry ('{}x{}'.format(w,h));
left_frame = Frame(root, width = w*0.8, height=400, bg='#988C89');
right_frame = Frame(root, bg='#988C89',  width = w*0.8, height=400 );


left_frame.grid_propagate(0);
right_frame.grid_propagate(0);

root.grid_rowconfigure(1, weight=1);
root.grid_columnconfigure(0, weight=1); 

visible = Frame (root,  width = w*0.8, height=400);
visible.grid(row=0, column=0, sticky="new");

如何调整可见框架的透明度?

如果我添加代码

 visible.attributes("transparentcolor","red")

我收到error : AttributeError: Frame instance has no attribute 'attributes'

还有代码

visible.configure(bg='#988C8900');

我收到error : tkinter.TclError: invalid color name "#988C8900"

我该怎么办?

【问题讨论】:

    标签: python tkinter frame


    【解决方案1】:

    你只是不能在 tkinter 中设置框架的透明度。但是你可以设置整个窗口的透明度 root.attributes('-alpha', 0.5)

    如果您使用的是 Windows,您也可以使用 root.attributes("-transparentcolor", "red"),但同样会应用于整个窗口。

    否则,您可以使用 Canvas 覆盖带有透明部分的 PNG 图像。

    【讨论】:

      猜你喜欢
      • 2014-06-03
      • 1970-01-01
      • 2013-10-06
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-23
      相关资源
      最近更新 更多