Код: Выделить всё
import tkinter as tk
from tkinter import ttk
class TestWgt(ttk.Labelframe):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
lbl_bg = ttk.Style().lookup(self['style'], "lbl_bg")
lbl_fg = ttk.Style().lookup(self['style'], "lbl_fg")
ent_bg = ttk.Style().lookup(self['style'], "ent_bg")
ent_fg = ttk.Style().lookup(self['style'], "ent_fg")
# self.config(foreground=fg_color, background=bg_color)
self.lbl = ttk.Label(self, text='do something:', background=lbl_bg, foreground=lbl_fg)
self.ent = ttk.Entry(self, background=ent_bg, foreground=ent_fg)
self.lbl.grid(row=0, column=0)
self.ent.grid(row=0, column=1)
if __name__ == '__main__':
root= tk.Tk()
stl = ttk.Style(root)
stl.theme_use('classic')
stl.configure('BigFont.TButton', font=(None, 15))
# you have to configure Labelframe twice... once for the frame, once for the label:
stl.configure('Test.TLabelframe',
lbl_bg='lightblue',
lbl_fg='blue',
ent_bg='white',
ent_fg='green',
background='#ffffaa'
)
stl.configure('Test.TLabelframe.Label',
background='#ffffaa',
foreground='#ff0000'
)
w = TestWgt(root, text='xyzzy', style='Test.TLabelframe', padding=20)
w.grid(row=0, column=0, sticky=tk.NSEW)
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
root.mainloop()