Is there any way to customize t开发者_如何学Che border color of a Tkinter/ttk
widgets or frames?
Yes, you can create your own style and apply it to the widget or configure the attributes of an existing style.
Some documentation and examples are in the official docs, specifically the section about ttk.Style.
Additional information on using styles (for several languages) can be found at tkdocs.com.
Regarding a border on ttk.Frames: in lieu of styles, the best I can think of is to insert a ttk.Frame within a ttk.Frame. The outer frame would use a standard "background" property with the border color of choice, and a padding equal to the desired border thickness. The inner frame then obscures the middle, so you have a line only around the edges. Works, but seems a little bit hacky (and a bit less wieldy if you're creating many widgets/borders).
I've searched quite a bit and haven't found or figured out a way to use a style to change a ttk.Frame's border color. Using something like style.configure( 'SeletectedItem.TFrame', highlightcolor='#78F', highlightthickness=2 )
or style.configure( 'SeletectedItem.TFrame', highlightbackground='#78F', highlightcolor='#78F', highlightthickness=2, borderwidth=2 )
(config options that work on a regular Tk.Frame) doesn't seem to do anything. With style.layout()
I find just [('Frame.border', {'sticky': 'nswe'})]
, and from style.element_options('TFrame.border'
) there is just ('-relief',)
. I don't know if I'm using the wrong option names or syntax (or what options are available for .configure()
for different widget classes), or if this just isn't possible with styles. I'm interested if anyone has extra info or knows if this can be done.
精彩评论