Padding specified in style ignored by Ttk Frame

核能气质少年 提交于 2019-12-05 16:13:05

The layout for the TFrame does not include a padding element so there is no style element to make use of the configured padding value in your style. You can see this by inspecting the layout:

>>> from tkinter import *
>>> from tkinter.ttk import *
>>> style = Style()
>>> style.theme_use('default') # select the Unix theme
>>> style.layout("TFrame")
[('Frame.border', {'sticky': 'nswe'})]

Looking at something that does use padding like a TButton:

>>> style.layout("TButton")
[('Button.border', {'border': '1', 'children':
    [('Button.focus', {'children': 
        [('Button.padding', {'children':
            [('Button.label', {'sticky': 'nswe'})],
        'sticky': 'nswe'})],
    'sticky': 'nswe'})],
'sticky': 'nswe'})]

In this layout we have a "border" element that will make use of borderwidth and relief configuration options. A focus element to deal with showing the focus ring. And also a padding element to include a configured amount of padding.

The TFrame style does not use any padding element. However, the Frame widget does use a widget padding value. This is used by the widget itself to define an internal padding when placing contained widgets. This is not covered by the style but as a widget specific option.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!