Try Pygame. It will not only allow you to display images, but it help you move them and interact with them. If you are planning to make a chess game, I'm sure Pygame will help! If you really want to stick to SVG then.... I guess I'm just trying to help.
if you want an example code please comment below. Hope this helps!
Ok I'm done. The game so far allows you to move the pieces in their allowed places. But the rest I'll leave up to you, since it will take a bit of time. If you need any guidance in pygame just comment again and I'll try to help. Here is the code:
import pygame, time, sys, random
from pygame.locals import *
# Initialize pygame (this is nessseccary for it to run all it's commands)
pygame.init()
# Draw the screen. The width and the height define how long and how wide the window is
width = 600
height = 500
window = pygame.display.set_mode((width, height))
TRANSwindow = window.convert_alpha()
# this sets the window title to "Chess!"
pygame.display.set_caption("Chess!")
# define some colours that we might need for later decoration
aqua = 0, 255, 255
black = 0, 0, 0
blue = 0, 0, 255
fuchsia = 255, 0, 255
gray = 128, 128, 128
green = 0, 128, 0
lime = 0, 255, 0
maroon = 128, 0, 0
navy_blue = 0, 0, 128
olive = 128, 128, 0
purple = 128, 0, 128
red = 255, 0, 0
silver = 192, 192, 192
teal = 0, 128, 128
white = 255, 255, 255
yellow = 255, 255, 0
# Make a group that contains the sprite pieces that we need
pieces = pygame.sprite.Group()
# Make a group that contains the grid called "board" that we need
grid = pygame.sprite.Group()
# Make a group that contains the allowed click spaces called "ClickSpaces" that we need
ClickSpaces = pygame.sprite.Group()
class Board(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load("yoHZB.png")
self.image = pygame.transform.scale(self.image,(600,500))
self.rect = self.image.get_rect()
class Piece(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load("Hr7mM.png")
self.image = pygame.transform.scale(self.image,(75,65))
self.rect = self.image.get_rect()
class ClickSpace(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.image = pygame.image.load("I6rbE.png")
self.image = pygame.transform.scale(self.image, (75, 65))
self.rect = self.image.get_rect()
for i in range(8):
piece = Piece()
piece.rect.x = i*75
piece.rect.y = 0
pieces.add(piece)
for i in range(8):
piece = Piece()
piece.rect.x = i*75
piece.rect.y = 65
pieces.add(piece)
for i in range(8):
piece = Piece()
piece.rect.x = i*75
piece.rect.y = 380
pieces.add(piece)
for i in range(8):
piece = Piece()
piece.rect.x = i*75
piece.rect.y = 440
pieces.add(piece)
board = Board()
grid.add(board)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
elif event.type == MOUSEBUTTONUP:
mouse = pygame.mouse.get_pos()
for piece in pieces:
if piece.rect.collidepoint(mouse):
print("clicked")
for i in range(2):
clickspace = ClickSpace()
clickspace.rect.x = piece.rect.left
clickspace.rect.y = piece.rect.top+((i+1)*65)
ClickSpaces.add(clickspace)
print("added clickspace")
ClickSpaces.draw(window)
pygame.display.update()
wait = True
while wait == True:
mouse = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
exit()
elif event.type == MOUSEBUTTONUP:
mouse = pygame.mouse.get_pos()
for clickspace in ClickSpaces:
if clickspace.rect.collidepoint(mouse):
print("clickspace clicked")
piece.rect.x = clickspace.rect.left
piece.rect.y = clickspace.rect.top
ClickSpaces.empty()
wait = False
else:
ClickSpaces.empty()
wait = False
window.fill(white)
grid.draw(window)
pieces.draw(window)
ClickSpaces.draw(window)
pygame.display.update()
Once you copied the code and put it in python. Save the project then download the following images and put them in the same file as your code:


