I'm working on a project to design a chessboard.
I have successfully created the board. My goal is to edit the board.
My original idea is to use buttons with the Tkinter grid to make the moves work.
I decided to make the board using:
window = tk.Tk() # Creating the GUI and Display
window.geometry("800x500")
window.minsize(800, 500) #Locking the size of the Display
window.maxsize(800, 500)
#Adding the board
SeenBoard = tk.Frame(window, width=300, height=300,padx=5,pady=5) #Adds padding to the grid
SeenBoard.pack(side=tk.LEFT) #the left isnt needed yet, but will be later
for row in range(8): # 8 Rows along
for column in range(8): #8 Columns down
tk.Button(SeenBoard,text=f"{row},{column}",width=5,height=3).grid(row=row, column=column) #Creates each button
window.mainloop() #Idk what this really does? it just kinda works.
My problem is that with this way of making the board, I cannot edit the buttons, nor locate them.
- I wish to be able to change the color of each button, to alternate between green and white, for that grid pattern feel.
- In order to do this I only can think of two ways at least, and that would be to somehow give each of the buttons an identifier beforehand, such as labeling them all as
Grid1_1.button(...) - My problem with doing it manually is that I want to keep the code concise and not repetitive, so anyway in which I could add lots of them at once would solve my problem.
Second solution to my knowledge:
- Somehow having the ability with Tkinter to select a specific grid slot, such as 2,2. and then trying to modify it with that, I heard about grid slaves, but I'm too small brained to understand how it works.
My request:
- I would like to know the solution or even the concept behind trying to alternate the color of the board in a pattern. any method
- Any solution that would allow me to access a button, and change its text/color.
