By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

Image does not display on tkinter chessboard

P: 2
Hi, i have this board made in python with tkinter to which i want to add an image of a king at a set location, the image doesnt display and i get no error, please help! thank you!

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
Feb 4 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.