I created a 7x7 field of buttons with a dictionary.
Problem 1: I need to disable a User-Input amount 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 usable. 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 :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…