i have a chessboard that i want to add an image of a king to, i add the image at a set location but the image doesn't appear on the board, please help!.
class GameBoard(tk.Frame):
def __init__(self, parent, rows=8, columns=8, size=70, color1="white", color2="lightgrey"):
'''size is in pixels'''
self.rows = rows
self.columns = columns
self.size = size
self.color1 = color1
self.color2 = color2
self.pieces = {}
canvas_width = columns * size
canvas_height = rows * size
tk.Frame.__init__(self, parent)
self.canvas = tk.Canvas(self, borderwidth=0, highlightthickness=0,
width=canvas_width, height=canvas_height, background="white")
self.canvas.pack(side="top", fill="both", expand=True, padx=2, pady=2)
self.canvas.bind("<Configure>", self.refresh)
def addPiece(self, image, row = 6 , columns = 6):
self.canvas.WhiteKing = tk.PhotoImage(file = 'E:\\Final Project + Report\\Pieces\\WhiteKing.png')
self.canvas.create_image(6,6, image = self.canvas.WhiteKing, anchor = NW)
def KingMoves(self, row, columns):
PossibleMoves = []
def refresh(self, event):
color = self.color2
for row in range(self.rows):
color = self.color1 if color == self.color2 else self.color2
for col in range(self.columns):
x1 = (col * self.size)
y1 = (row * self.size)
x2 = x1 + self.size
y2 = y1 + self.size
self.canvas.create_rectangle(x1, y1, x2, y2, outline="black", fill=color, tags="square")
color = self.color1 if color == self.color2 else self.color2