Image does not display on tkinter chessboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sharjeel1234567
    New Member
    • Feb 2018
    • 2

    Image does not display on tkinter chessboard

    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.Fr ame):
    def __init__(self, parent, rows=8, columns=8, size=70, color1="white", color2="lightgr ey"):
    '''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, highlightthickn ess=0,
    width=canvas_wi dth, height=canvas_h eight, background="whi te")
    self.canvas.pac k(side="top", fill="both", expand=True, padx=2, pady=2)

    self.canvas.bin d("<Configure>" , self.refresh)

    def addPiece(self, image, row = 6 , columns = 6):
    self.canvas.Whi teKing = tk.PhotoImage(f ile = 'E:\\Final Project + Report\\Pieces\ \WhiteKing.png' )
    self.canvas.cre ate_image(6,6, image = self.canvas.Whi teKing, 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.colu mns):
    x1 = (col * self.size)
    y1 = (row * self.size)
    x2 = x1 + self.size
    y2 = y1 + self.size
    self.canvas.cre ate_rectangle(x 1, y1, x2, y2, outline="black" , fill=color, tags="square")
    color = self.color1 if color == self.color2 else self.color2
Working...