Configure tkinter/ttk widgets with transparent backgrounds, ttk frame background colors?
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 cust开发者_如何学Com 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).
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.)
精彩评论