如何设置tkinter框架的透明度 [英] how to set the transparency of the tkinter frame

查看:857
本文介绍了如何设置tkinter框架的透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python 2.7版

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

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

How do I adjust the transparency of a visible frame?

如果我添加代码

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

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

和代码

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

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

我该怎么办?

推荐答案

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

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)

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

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

否则,您可以使用Canvas用透明部分覆盖PNG图像.

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

这篇关于如何设置tkinter框架的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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