how to set the transparency of the tkinter frame

非 Y 不嫁゛ 提交于 2019-12-02 08:47:52

问题


python version 2.7

code;

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");

How do I adjust the transparency of a visible frame?

If I add the code

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

I get error : AttributeError: Frame instance has no attribute 'attributes'

and with code

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

I get error : tkinter.TclError: invalid color name "#988C8900"

What should I do?


回答1:


You just cannot set the transparency of the frame in tkinter. But you can set the transparency of the whole window with root.attributes('-alpha', 0.5)

You can also do root.attributes("-transparentcolor", "red") if you are using Windows, but again it will be applied to the whole window.

Otherwise, you can overlay PNG images with transparent parts using a Canvas.



来源:https://stackoverflow.com/questions/49271399/how-to-set-the-transparency-of-the-tkinter-frame

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!