4

I'm new to python and i just want to create a button with some arguments. But i can't succeed to have the background color or the relief, but the font works so i really don't understand what's going on.

from tkinter import *

window = Tk()

window.title("test bouton")
window.geometry("400x400")
button = Button(window, text="click me", fg='blue',  background='grey', relief='sunken')
button.pack()

window.mainloop()

With all the things i saw online i can't find my mistake, can you help me?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328

1 Answers1

0

We can not change background, relief, overrielf, activebackground, and maybe a few other options of a button on a mac system. You can take a look at this post.

If you are comfortable in using external libraries then you can try tkmacosx. Button of tkmacosx module will let you eliminate those limitations on mac.

Example:

from tkinter import *
from tkmacosx import Button

window = Tk()

window.title("test bouton")
window.geometry("400x400")
button = Button(window, text="click me", fg='blue', bg='grey', borderless=1)
button.pack()

window.mainloop()

To use relief=sunken you have to set the borderwidth (or bd) more than 1.

Button(window, text="click me", fg='blue', bg='grey', relief='sunken', bd=3)
Saad
  • 3,340
  • 2
  • 10
  • 32