Reputation: 84
I want to see what all options I can modify on a ttk widget. I used the style.layout()
method but I am not sure if all the options are being printed. I want to change ttk.Labelframe
label fg and bg but I can not see any of those options in the style.layout()
method. I found the answer online, it is done like so: style.config(TLabelframe.Label, **options)
and it works. But I am curious as to why it doesnt print on my console (obviously nothing wrong with the console, maybe I am not printing the right methods). It works for TButton
though, exact same print statements. I cant find TLabelframe.Label
in the prints. Can someone explain me where I am going wrong and how to get all the options I can use for styling a particular widget? Thanks in advance
import tkinter as tk
from tkinter import ttk
from pprint import pprint
from tkinter.font import Font
root = tk.Tk()
lf = ttk.Labelframe(root, text='Labelframe')
btn = ttk.Button(lf, text='Whatever')
btn_font = Font(
family='Helvetica',
size=20,
weight='bold',
underline=True
)
style = ttk.Style()
style.configure(
'TButton', font=btn_font,
foreground='white',
background='black',
width=20
)
lf.pack()
btn.pack()
print('----Labelframe----')
print(lf.winfo_class())
print(style.layout('TLabelframe'))
print('\nLabelframe.border\n')
print(style.element_options('Labelframe.border'))
print(style.map('TLabelframe'))
print(style.element_options('Labelframe.Label'))
print('----Button----')
print(f'Type: {type(btn)}')
print(f'Class: {btn.winfo_class()}')
print(f'Layout: {style.layout(btn.winfo_class())}')
btn_label =style.element_options('Button.label')
print(f'Button.label ---> {btn_label}')
btn_focus = style.element_options('Button.focus')
btn_pad = style.element_options('Button.padding')
btn_border = style.element_options('Button.border')
print(f'Button.focus ---> {btn_focus}')
print(f'Button.border ---> {btn_border}')
print(f'Button.padding ---> {btn_pad}')
print(style.map('TButton'))
root.mainloop()
Output:
----Labelframe----
TLabelframe
[('Labelframe.border', {'sticky': 'nswe'})]
Labelframe.border
('background', 'borderwidth', 'relief')
{}
()
----Button----
Type: <class 'tkinter.ttk.Button'>
Class: TButton
Layout: [('Button.border', {'sticky': 'nswe', 'border': '1', 'children': [('Button.focus', {'sticky': 'nswe', 'children': [('Button.padding', {'sticky': 'nswe', 'children': [('Button.label', {'sticky': 'nswe'})]})]})]})]
Button.label ---> ('compound', 'space', 'text', 'font', 'foreground', 'underline', 'width', 'anchor', 'justify', 'wraplength', 'embossed', 'image', 'stipple', 'background')
Button.focus ---> ('focuscolor', 'focusthickness')
Button.border ---> ('background', 'borderwidth', 'relief')
Button.padding ---> ('padding', 'relief', 'shiftrelief')
{'relief': [('!disabled', 'pressed', 'sunken')]}
Upvotes: 1
Views: 35