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

Tkinter图片按钮边框无法移除求助:设置borderwidth=0后仍存在边框

Fixing the Persistent Border on tkmacosx Image Buttons

Hey there! I see you're struggling with that stubborn border sticking around on your image button even after setting borderwidth=0—let's get that sorted out. The issue here is that tkmacosx.Button has a couple more styling parameters that contribute to visible borders, beyond just borderwidth.

Key Fixes to Add

The two critical settings you're missing are:

  • highlightthickness: This controls the thickness of the focus highlight border (it defaults to a non-zero value on macOS, which creates that faint outline)
  • relief: This sets the button's 3D bevel appearance—setting it to flat removes any inherent raised or sunken edge

Updated Image Button Code

Modify your image button declaration to include these parameters:

theme1 = PhotoImage(file = "/Documents/theme1button.png")
theme1Button = Button(
    root, 
    image=theme1, 
    borderwidth=0, 
    background=selectedBackground, 
    command=openCipher,
    highlightthickness=0,  # Removes the focus highlight border
    relief="flat"          # Eliminates any built-in 3D bevel
)
theme1Button.place(x=50, y=100)

Quick Checks to Rule Out Other Issues

  1. Verify the image file: Make sure your theme1button.png doesn't have an embedded border in the image itself. Test with a solid-color image to confirm the button settings are working.
  2. No Canvas required: Your guess about needing a Canvas is incorrect—you don't need to place the button on a Canvas to remove the border. The problem is entirely with the button's own styling parameters.

Give these changes a go, and that unwanted border should disappear completely!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.27 20:08:12