How Can I Change The Background Color Of A Button Using Tkinter On MacOs Big Sur

Viewed 131

Expected Behavior

I should get an output like this:

Observed behavior

What I got:

The Code

from tkinter import *

root = Tk()


def my_click():
    my_label = Label(root, text='Look! I clicked a button!')
    my_label.pack()


my_button = Button(root, text='Click Me!', command=my_click, bg='#6d35e6', fg='#0000ff')
my_button.pack()

root.mainloop()

Update On The Code

I'm using an attribute called highlightbackground instead of bg for the background. You can check the comment that I made for further details.

Version Info

System Os: MacOs Big Sur 11.3 (LTS)
Python Version: 3.9.4 (LTS)
Tkniter Version: 8.6 (LTS)
Code Editor: PyCharm CE Community 2021.1.1 (LTS)
0 Answers
Related