简体   繁体   中英

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 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).

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM