I am trying to build a simple game of Connect Four with Python(2.7)
I have created a board, that consists of a simple multidimensional Python list.
My Board list looks like this:
board = [
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,_,_,_,_,_,_],
[_,_,_,_,O,_,_,_,_,_],
[_,_,_,_,X,_,_,_,_,_],
[_,_,_,_,X,O,_,_,_,_],
[_,_,_,_,X,O,_,_,_,_],
]
Were X is Player1 and O is Player2 (or Computer).
Now, I have created some basic code for the GUI, like this:
# Connect 4 Game
import Tkinter
screen = Tkinter.Tk()
screen.title("My First Game")
#Create a board
board = Tkinter.Canvas(screen,width=500,height=500)
board.pack()
screen.mainloop()
Question: How can i create a visual representation of the board, so that for every element, there is a rectangle? Also, is there a way to detect, when a rectangle is clicked and replace the corresponding list value?
['_']
,['X']
, or['O']
. Shouldn't they just be elements, like'_'
,'X'
, or'O'
? – Brinson