Im trying to make my first Tkinter project and decided on a Chess game. Ive written most of the basic program but when I tried to execute the pre-programmed pawn movements the pawn images don't change even tho it seems like the module registers the movement.
Here is all the details:
The widget structure is just one frame with label widgets placed in a grid representing a classical chess board.
My program has two classes, boot and move. Both is called (instantiated?) directly. Boot creates the board layout and also the object called game containing two nested dictionaries game.pawns and game.squares .
game.pawns
game.pawns contains information about each pawn such as position ect and is reached like: game.pawns['B_Bishop_C']['pos'] where first letter is the color and the last letter is the horizontal starting position. More details about dictionary keys and values are the code (line 25) found in git.
game.squares
game.squares contains information about the squares such as if it is occupied and by which pawn. Also very importantly it contains the label widget with key ['wdgt']. Each square is reached with a string: '0 to 7' + 'A to H' so regular chess positioning but with one less index. Ex Upper left '0A', down right '7H'.
Ex: game.squares['0B']['widget'] would access the label widget where a black knight is standing (white at bottom).
Problem
So back to the problem: For some reason when I try to .config the label to change the image it doesn't change even tho the imaged shows as it is added with the winfo command.
Code
Here is the code where called when I move a pawn to a empty square(where the error is)
img = game.pawns[self.current_pawn]['img']
game.squares[pos]['wdgt'].image = img
game.squares[pos]['wdgt'].config(image=img)
#replace image of target square to the new pawn
game.squares[game.pawns[self.current_pawn]['pos']]['occ'] = None
#Changes occ of old square
game.pawns[self.current_pawn]['pos'] = pos
#changes moving pawn attribute position to new
game.squares[game.pawns[self.current_pawn]['pos']]['wdgt'].config(image = '')
#remvoes pawn from old square
game.squares[pos]['occ'] = pawn
#Changes occ of new square
Here is my GitHub:
https://gits-15.sys.kth.se/markusjs/Chess
Note:
Code from above is around line 250.
self.current_pawn is in same form as dict key for game.pawns
To run the code PIL and Tkitner is needed.
Also pawns must be in the folder with the relative path given when creating the pawns at line 122-149
From line 300 and down is only pawn movement code.
There are probably some undiscoverd problems in the program
Things I tried:
Referencing image.
Using image without alpha (transparency).
Tkinter Label does not show Image
All help is appreciated.