我正在尝试从python-chess SVG渲染工作中获得此代码示例。
import chess
import chess.svg
chess.svg.piece(chess.Piece.from_symbol("R"))
当我运行代码时,我得到以下HTML输出,但不是白车的图像。
<svg version="1.1" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g class="white rook" fill="#fff" fill-rule="evenodd" id="white-rook" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M9 39h27v-3H9v3zM12 36v-4h21v4H12zM11 14V9h4v2h5V9h5v2h5V9h4v5" stroke-linecap="butt" /><path d="M34 14l-3 3H14l-3-3" /><path d="M31 17v12.5H14V17" stroke-linecap="butt" stroke-linejoin="miter" /><path d="M31 29.5l1.5 2.5h-20l1.5-2.5" /><path d="M11 14h23" fill="none" stroke-linejoin="miter" /></g></svg>
这就解决了我的问题:
import chess
import chess.svg
import IPython
html_code = chess.svg.piece(chess.Piece.from_symbol("R"))
display(IPython.display.HTML(html_code))
,现在白车显示在Colab。