Configure tkinter/ttk widgets with transparent backgrounds, ttk frame background colors?

∥☆過路亽.° 提交于 2021-02-07 12:25:46

问题


Is it possible to configure tkinter or ttk widgets (Label, Entry, Text) with a transparent background so that they can be placed in containers with custom background colors or on top of canvas graphics or images?

I'm also looking for a way to change the background color of a ttk Frame widget?

Do I need to use the new ttk Style objects to accomplish the above? (I'm new to tkinter/ttk and still trying to get my head around the proper way to do things).


回答1:


Except on OSX, what you want can't be done because all those widgets are drawn on real windows which are rectangular (unless you use some low-level tricks to chop holes out of the window concerned; not an approach I recommend even though I've got code – for Tcl/Tk, not Python/Tkinter admittedly – which does it). OSX is the exception because there widgets (mostly) aren't drawn on real windows, but rather use a lighter-weight system (because that's how OSX works).

You can tune the widgets to have less of a border than normal, which is OK if you're using a style that keeps them fundamentally square. Or if you're using a canvas for your “interesting” surface, you can build button-like things on the canvas which may well be better for what you're actually doing.

To change the background color of a Ttk frame, you'll have to apply a style to it. The best instructions on style creation I've seen so far are in the tkdocs style tutorial, which is where I go when I want to look up how to do these things. (Yes, the Ttk documentation ought to cover this itself, but it doesn't yet.)



来源:https://stackoverflow.com/questions/4011406/configure-tkinter-ttk-widgets-with-transparent-backgrounds-ttk-frame-background

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