2

I have a simple python code on my Mac, tryin to change background color of a button, in a tkinter window:

from tkinter import *
w=Tk()
def change():
    b.config(bg='yellow')
b=Button(w,text='CHANGE',command=change)
b.pack()
w.mainloop()
1

2 Answers 2

1

Tkinter uses tk, and tk uses native toolkits, and on OSX the native toolkits don't allow you to change the background color of buttons.

Sign up to request clarification or add additional context in comments.

2 Comments

thx. but so why I can change foreground color of the button but not background?
@Tommy you'll probably have to ask Apple that question.
0

Here is link: tkmacosx

Snippet:

from tkinter import Tk
from tkmacosx import Button

root = Tk()
root.geometry('200x150')
B0 = Button(root, text='Button')
B0.pack(padx=20, pady=(20,0))
B1 = Button(root, text='Button', bg='#ADEFD1',
            fg='#00203F', borderless=1)
B1.pack(padx=20, pady=10)
B2 = Button(root, text='Button', bg='#E69A8D',
            fg='#5F4B8B', borderless=1,
            activebackground=('#AE0E36', '#D32E5E'),
            activeforeground='#E69A8D')
B2.pack()
root.mainloop()

screenshot:

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.