jeudi 14 décembre 2017

Python Tkinter - Dictionary with Buttons - how do you disable them?

i created a 7x7 field of Buttons with a dictionary. Problem 1: I need to disable a User-Input amout of buttons randomly. The User writes a number x and x buttons will be blocked, but my program has to choose them randomly...

Problem 2: The Rest of the buttons are useable. But if you click one, they will change the color and get state=tk.DISABLED.

How do i do all that with a dictionary full of buttons?

    buttons = {}
    for x in range(0, 7):
        for y in range(0, 7):
            buttons[tk.Button(frame_2, height=5, width=10, bg="yellow",command=self.claim_field)] = (x, y)
    for b in buttons:
        x, y = buttons[b]
        b.grid(row=x, column=y)
def claim_field():
    #changing Color of button and blocking the same button

Thank you for your answers, sorry for my bad english :)




Aucun commentaire:

Enregistrer un commentaire