python-chess SVG rendering?

1,410 views
Skip to first unread message

Sean

unread,
Jan 30, 2021, 12:46:13 PM1/30/21
to PicoChess
I wondered if anybody here had experience of using the python-chess library SVG rendering? It looks quite well featured.

Thanks,
Sean

Jesse Black

unread,
Apr 29, 2021, 7:34:08 PM4/29/21
to PicoChess
Hi Sean,

Yes I’ve done this. I wrote a small python program using Python-Chess library. It takes in a FEN string and outputs an SVG of the board. In fact, it can even take in a PGN string and output an animated gif of the whole game which is really cool. 

It’s the first part of a larger project I am working on. The library is very well featured however there may not be that many options to customise the SVG. I’m still trying figure that part out. 

Cheers
Jesse

Sean

unread,
Apr 30, 2021, 10:38:50 AM4/30/21
to PicoChess
Hi Jesse,
That's great - thanks for replying.
I tried as best I could to produce any graphical output and failed.  The library seems so full featured, I'd love to make use of the SVG too.
I'm clearly missing something (probably basic) and none of my internet searches have shown up any examples.
Would you possibly mind sharing your small program? or part of it? Anything that displays 'something'.
I used to be a C programmer and took up Python for a hobby about a year ago (to use on the RPi). If I can see how it's being used (additional libraries?), I should be able to get it to work.

Many thanks,
Sean

Jesse Black

unread,
May 1, 2021, 6:36:33 AM5/1/21
to PicoChess
Hi Sean,

No worries, it also took me quite a bit of time with the docs to figure it out. 

I've attached a small program (20 lines) that will take in the FEN string for the starting position on the board and render the SVG, then write the file to your working directory. That was the part that tripped me up. Once you render the SVG you then have to write it to disk. 

Hopefully this helps and let me know how it goes!

Cheers,

Jesse
python_chess_svg_example.py

Sean Taylor

unread,
May 4, 2021, 1:34:37 AM5/4/21
to pico...@googlegroups.com
Hi Jesse,
Thanks. I can see the SVG image when opening the file.
How would I go about displaying the SVG on screen along with updates? [ Use a GUI that handles .svg? I don't think guizero does].
Thanks,
Sean

--
You received this message because you are subscribed to a topic in the Google Groups "PicoChess" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/picochess/QbnEav-J67A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to picochess+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/picochess/aca6ca3c-209d-4937-abb0-f902c774ee27n%40googlegroups.com.

Sean Taylor

unread,
May 4, 2021, 1:34:46 AM5/4/21
to pico...@googlegroups.com
Hi Jesse,
That's great - thanks for replying.
I tried as best I could to produce any graphical output and failed.  The library seems so full featured, I'd love to make use of the SVG too.
I'm clearly missing something (probably basic) and none of my internet searches have shown up any examples.
Would you possibly mind sharing your small program? or part of it? Anything that displays 'something'.
I used to be a C programmer and took up Python for a hobby about a year ago (to use on the RPi). If I can see how it's being used (additional libraries?), I should be able to get it to work.
You can email me direct if you prefer (se...@alittlemusic.com).

Many thanks,
Sean

--
You received this message because you are subscribed to a topic in the Google Groups "PicoChess" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/picochess/QbnEav-J67A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to picochess+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages