Home > database >  Does configuration on tkinter buttons always work?
Does configuration on tkinter buttons always work?

Time:06-01

I'm working on a code that has all the letters on the screen as buttons. When you click the button, the background color should become red and the button should become disabled. Here's what I have so far:

import tkinter as tk
import string as s

root = tk.Tk()
root.title('Test')
root.geometry('1100x1100 10 10')

letters = tk.Frame(root)
letters.place(x=500, y=300)
letter_dict = {l:n for n, l in enumerate(s.ascii_lowercase)}
letter_buttons = [(tk.Button(letters, text=(l.upper()), padx=20, pady=20, font=('Times New Roman', '25'), state='normal', command=lambda l=l: take_out_button(l))) for l in s.ascii_lowercase]

def place_lt_btns():
    global letter_buttons
    #letter_buttons[0].grid(row=0, column=0)
    columnnum = 0
    rownum = 0
    for num, i in enumerate(letter_buttons):
        if num < 24:
            i.grid(row=rownum, column=columnnum)
            columnnum  = 1
            if columnnum == 6:
                rownum  = 1
                columnnum = 0
        else:
            if num == 24:
                i.grid(row=4, column=2)
            elif num == 25:
                i.grid(row=4, column=3)

place_lt_btns()

def take_out_button(l):
    n = letter_dict[l]
    letter_buttons[n].config(bg='red', state='disabled')

Clearly, I am using .config to change the bg to 'red' and the state to be 'disabled'. It seems odd that one is working and one is not... Does anyone know why? The error is that the background isn't changing to red for the letter button when it is clicked.

CodePudding user response:

@BryanOakley stated in the comments "You can't change the background color of buttons on OSX." (read the whole discussion in the comments)

  • Related