You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Tkinter ttk.Button背景色溢出边框问题求助

自定义Tkinter按钮背景色溢出边框问题

![边框外的颜色]

以下是自定义按钮的代码:

style.configure('Dark.TButton', background=button_base, foreground=colors['text'], borderwidth=1,
    bordercolor=edge, lightcolor=edge, darkcolor=edge, padding=(10, 4))
style.map('Dark.TButton',
     background=[('pressed', pressed_bg or hover_bg or button_base),
              ('active', hover_bg or button_base),
              ('!disabled', 'red')],
       foreground=[('active', colors['text']), ('pressed', colors['text'])],
       bordercolor=[('pressed', edge), ('active', edge)],
       lightcolor=[('pressed', edge), ('active', edge)],
       darkcolor=[('pressed', edge), ('active', edge)])
        
style.layout('Dark.TButton', [
    ('Button.border', {'sticky': 'nswe', 'children': [
        ('Button.padding', {'sticky': 'nswe', 'children': [
            ('Button.label', {'sticky': 'nswe'})
        ]})
    ] })
])

为了让问题更直观,我把按钮背景色设成了红色。试过增大borderwidth参数,结果只是让边框整体外扩,厚度并没有变化,背景色溢出边框的问题依然存在。

用原生Tk.Button不会出现背景溢出的情况,但会丢失按钮的斜面边框效果:

![完整UI展示]

内容的提问来源于stack exchange,提问作者Maj mac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 00:04:53