简体   繁体   中英

Tkinter button background color is not working in mac os

I am trying to change the bg color of a tkinter button on my mac (catalina) but instead of getting a colored background, it is showing a blank space in the layout.

The button code I used:

OpeningFile = Button(root, width=45, bg="#82CC6C", fg="black", text="OPEN", highlightbackground="#82CC6C", highlightthickness=1, borderwidth=0.2, relief="groove", padx=0, pady=0, command=openfile)

OpeningFile.grid()

Result I am getting:

错误按钮

What I expected:

预期结果

I tried changing many parameters but it is still giving me the same result,

Can it be fixed or it is a bug in tkinter inside mac only? (It was working properly in windows)

I was looking for information on the same issue and it seems to be a limitation with tkinter using the MacOS APIs. Basically MacOS says the button colors can't change so tkinter can't change them.

https://github.com/python/cpython/issues/88409

I got the fix:

Use tkmacosx module for tkinter buttons in mac, use "from tkmacosx import Button", and then change the parameters and use borderless=1 to remove the unnecessary layout. You can see the result I got after using the module:

macOS 截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM