Tkinter图片按钮边框无法移除求助:设置borderwidth=0后仍存在边框
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 toflatremoves 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
- Verify the image file: Make sure your
theme1button.pngdoesn't have an embedded border in the image itself. Test with a solid-color image to confirm the button settings are working. - 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
相关产品推荐
相关产品推荐

