Skip to main content

ChessBoard - a Kivy Widget to interact with a Chess Board

This package provides a chess board as a kivy widget. It allows users to interact with the chess board by dragging and dropping pieces, and it can be integrated into Kivy applications.

The widget displays the current state of a chess.Board from the python-chess library. It supports highlighting specific moves and selecting squares. By design, it does not implement any game logic or enforce chess rules; it simply reflects the state of the provided chess.Board and notifies the host application of user interactions.


Exmaple Usage

See the documentation for more details and full API reference.

import chess
from kivy.app import App
from kivy.config import Config as KivyConfig
from kivy.logger import LOG_LEVELS, Logger
from kivy.uix.floatlayout import FloatLayout
from kivy.utils import platform

from kivy_chess_board import ChessBoard


class MyApp(App):
    def build(self):
        root = FloatLayout()
        cb = ChessBoard()
        cb.highlight_hover_when_dragged = True
        root.add_widget(cb)

        # At any time we can set the board to a specific position and highlight
        # moves.
        cb.update(
            chess.Board(),
            moves_to_be_highlighted=[
                chess.Move.from_uci("e2e4"),
                chess.Move.from_uci("d2d4"),
            ],
            move_selector=0,  # e2e4 move appears "selected"
        )

        cb.process_square_selection = process_square
        cb.process_move_selection = process_move
        return root


def process_square(cb: ChessBoard, pos: chess.Square) -> None:
    """Callback to process square selections (clicks as well as drag-and-drop)."""
    cb.squares_to_be_highlighted = [pos]
    square_name = chess.square_name(pos)
    Logger.debug(f"App: Square selected: {square_name}")


def process_move(cb: ChessBoard, move: chess.Move) -> None:
    """Callback to process move selection."""
    if move not in cb.board.legal_moves:
        Logger.warning("App: Illegal move")
        return

    cb.board.push(move)
    cb.update()

    # flip board after each move, this will only be slow the first time when
    # the assets for the inverted board are loaded
    cb.inverted = not cb.inverted

    cb.moves_to_be_highlighted = [move]  # highlight last move
    cb.squares_to_be_highlighted = []


def adjust_kivy_config() -> None:
    """Remove weird touchpad behavior on Linux.

    This is a bug in Kivy itself, not specific to this progream."""
    if platform != "linux":
        return

    if KivyConfig is None or not KivyConfig.has_section("input"):
        return

    for opt in list(KivyConfig.options("input")):
        if KivyConfig.get("input", opt) == "probesysfs":
            KivyConfig.remove_option("input", opt)


Logger.setLevel(LOG_LEVELS["debug"])
adjust_kivy_config()
MyApp().run()

Licensing

ChessBoard is free and open source software licensed under the GNU General Public License v3.0 or later.

Third-party notices, including details for redistributed derived artwork assets, are listed in NOTICE.

Metadata

Release files for kivy-chess-board 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kivy-chess-board 1.0.5
File Size Uploaded Provenance Actions
kivy_chess_board-1.0.5.tar.gz 348.6 kB Without provenance Details for kivy_chess_board-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kivy-chess-board 1.0.5
File Interpreter ABI Platform Actions
kivy_chess_board-1.0.5-py3-none-any.whl Python 3 none any Details for kivy_chess_board-1.0.5-py3-none-any.whl

Total release size: 702.2 kB

Release files / kivy_chess_board-1.0.5.tar.gz

Download URL kivy_chess_board-1.0.5.tar.gz
Size 348.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a83e35b3626a09464cedb8bb7568d306c7bc994874792a0970ba60f55a794e39
BLAKE2b-256 checksum
How to use checksums
bd01b03548d728d3aeb41483a4cc0e709af02a80f490d4d91a4bd3d19080859f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.5","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / kivy_chess_board-1.0.5-py3-none-any.whl

Download URL kivy_chess_board-1.0.5-py3-none-any.whl
Size 353.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8acfea9dbabc30bbc0230990778fe9ee1d1b3a0c97a4d300532fa4c33d49b61
BLAKE2b-256 checksum
How to use checksums
1ebf38e3b41e53d31146273c50620262a0a8707c2692b7878b4867e528576e37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.10 {"installer":{"name":"uv","version":"0.12.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.23.5","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for kivy-chess-board 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page