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"
我该怎么办?
答案 0 :(得分:2)
您无法在tkinter中设置框架的透明度。但您可以使用设置整个窗口的透明度
root.attributes('-alpha', 0.5)
如果您使用的是Windows,也可以root.attributes("-transparentcolor", "red")
,但它也会应用到整个窗口。
否则,您可以使用Canvas
将透明部分覆盖PNG图像。