Skip to main content

A PySide6 chess board widget

Project description

Python Chess Widgets

Tests codecov PyPI - Python Version

A modern, feature-rich chess board widget for PySide6 applications, designed to mimic the visual style and user experience of Lichess. It is built on top of the powerful python-chess library.

Fool's Mate Demo

Features

  • Lichess-like Aesthetics: Uses standard Lichess colors, SVG piece sets, and highlighting styles.
  • Interactive: Supports both drag-and-drop and click-to-move interactions.
  • Smooth Animations: Piece movements are animated for a better user experience.
  • Visual Indicators:
    • Legal move highlights (dots for empty squares, rings for captures).
    • Last move highlighting.
    • Check indicator (red blurred glow behind the king).
    • Selected piece and hover highlights.
  • Responsive: The board maintains its square aspect ratio and centers itself within the widget, scaling to fit the available space.
  • Board Flipping: Easily toggle between White and Black perspectives.
  • Type Safe: Fully typed codebase with mypy support (PEP 561 compliant).

Installation

You can install the package from PyPI:

pip install chess-widgets

Usage

Here is a simple example of how to use the BoardWidget in a PySide6 application:

import sys
import chess
from PySide6.QtWidgets import QApplication, QMainWindow
from chess_widgets import BoardWidget

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Chess Board Example")
        self.resize(600, 600)

        # Create the widget
        self.board_widget = BoardWidget()
        self.setCentralWidget(self.board_widget)

        # Connect to the move signal
        self.board_widget.move_played.connect(self.on_move_played)

        # Optional: Set an initial board state (defaults to starting position)
        # self.board_widget.set_board(chess.Board())

    def on_move_played(self, move: chess.Move, move_info: dict):
        interactive = move_info.get("interactive", False)
        print(f"{'Interactive' if interactive else 'Programmatic'} move: {move}")
        # The widget updates its internal board automatically for user moves.
        # You can access the board state via:
        # print(self.board_widget._board.fen())

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

A more complex example with move history navigation, board flipping, and random moves played for the opposite color can be found in the examples/demo.py file.

Demo

API Overview

  • set_board(board: chess.Board): Sets the board state to display.
  • set_flipped(flipped: bool): Sets the board orientation (True for Black at bottom, False for White at bottom).
  • play_move(move: chess.Move, animate: bool = True, interactive: bool = False): Programmatically make a move on the board, optionally with animation.
  • undo_move(move: chess.Move, animate: bool = True): Programmatically unmake the last move on the board, optionally with animation.
  • move_played(chess.Move, dict): Emitted when a move is played. The dictionary contains move information (e.g., {'interactive': True}).
  • move_undone(chess.Move): Emitted when a move is undone.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for details on how to set up your development environment and submit changes.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chess_widgets-0.5.0.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chess_widgets-0.5.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file chess_widgets-0.5.0.tar.gz.

File metadata

  • Download URL: chess_widgets-0.5.0.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chess_widgets-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a27382de47275a4612188b04873e9a51f527ec8d9b09a6f734b802400e6b53eb
MD5 18676aa07e1d3dbea37ab561f11270f1
BLAKE2b-256 fc39200fd9e0aec356140b898b79331a8f33c1282b5fe0c6d160d2b4c4acbbb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for chess_widgets-0.5.0.tar.gz:

Publisher: publish.yml on leszekhanusz/chess-widgets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chess_widgets-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: chess_widgets-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for chess_widgets-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 120bbd7516a57736d00a9d27384f0e2b19395c83cc78a2ae71a1f379e746c14c
MD5 8d3cbdcb0e5138812ef4f3c4030a71bd
BLAKE2b-256 3d6034cf91c7aa36713938bb15c8fffbe3297c55613c626deda4a0d28189f27a

See more details on using hashes here.

Provenance

The following attestation bundles were made for chess_widgets-0.5.0-py3-none-any.whl:

Publisher: publish.yml on leszekhanusz/chess-widgets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page