0

I have a 10x10 grid of buttons and have seen that the normal bg=colour parameter will not work on Mac so I am using the code below:

for x in range(10):
    for y in range(10):
        btn = Button(frame, highlightbackground='dark slate gray')
        btn.config(height=1, width=1)
        btn.grid(column=x, row=y, sticky=N+S+E+W)

When I first run the program they look a translucent green with a dark green border which is fine, but when I click the buttons there is no longer the visual queue that the button is being clicked. Strangely, I have a simple quit button at the bottom of my program:

quit_game = Button(root, text='Quit', border=10, font=('Helvetica', 16), highlightbackground='red3', fg='white', command=end_game, highlightthickness=1)
quit_game.grid(row=15, column=0, columnspan=12)

and when I click this button and choose no so the program continues, the buttons (including the quit button) lose their colour but start to show the reaction to the click again!

My question is what am I doing wrong/how else could I do this on Mac and avoid these issues?

aidakemind
  • 33
  • 6
  • is `btn.grid(column=x, row=y, sticky=N+S+E+W)` working for you? I think sticky assignment should be like this `sticky='nsew'` – JacksonPro Dec 16 '20 at 13:20
  • @JacksonPro tried it with your suggestion and works the same as before so I assume they are equivalent? Went with your way as it looks neater, thanks! – aidakemind Dec 16 '20 at 13:23
  • does this answer your question: https://stackoverflow.com/questions/1529847/how-to-change-the-foreground-or-background-colour-of-a-tkinter-button-on-mac-os – JacksonPro Dec 16 '20 at 13:34
  • @JacksonPro this post is where I found the solution of using highlightbackground - the ttk solution doesn't change the button colour (at least not on my machine) – aidakemind Dec 16 '20 at 13:52
  • did you try: `from tkmacosx import Button`? – JacksonPro Dec 16 '20 at 13:54
  • @JacksonPro I was looking for a more generic solution because it might not just be run on mac :( – aidakemind Dec 16 '20 at 14:02
  • @JacksonPro: the `sticky` argument is just a string, tkinter doesn't care how you define the string. `'nsew'` and `N+S+E+W` are functionally identical. – Bryan Oakley Dec 16 '20 at 15:03

0 Answers0