A PySide6 chess board widget
Project description
Python Chess Widgets
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.
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
mypysupport (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.
API Overview
set_board(board: chess.Board): Sets the board state to display.set_flipped(flipped: bool): Sets the board orientation (Truefor Black at bottom,Falsefor 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a27382de47275a4612188b04873e9a51f527ec8d9b09a6f734b802400e6b53eb
|
|
| MD5 |
18676aa07e1d3dbea37ab561f11270f1
|
|
| BLAKE2b-256 |
fc39200fd9e0aec356140b898b79331a8f33c1282b5fe0c6d160d2b4c4acbbb8
|
Provenance
The following attestation bundles were made for chess_widgets-0.5.0.tar.gz:
Publisher:
publish.yml on leszekhanusz/chess-widgets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chess_widgets-0.5.0.tar.gz -
Subject digest:
a27382de47275a4612188b04873e9a51f527ec8d9b09a6f734b802400e6b53eb - Sigstore transparency entry: 720811069
- Sigstore integration time:
-
Permalink:
leszekhanusz/chess-widgets@c86b19858814764f99b21adf2fd0739b15a3759d -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/leszekhanusz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c86b19858814764f99b21adf2fd0739b15a3759d -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
120bbd7516a57736d00a9d27384f0e2b19395c83cc78a2ae71a1f379e746c14c
|
|
| MD5 |
8d3cbdcb0e5138812ef4f3c4030a71bd
|
|
| BLAKE2b-256 |
3d6034cf91c7aa36713938bb15c8fffbe3297c55613c626deda4a0d28189f27a
|
Provenance
The following attestation bundles were made for chess_widgets-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on leszekhanusz/chess-widgets
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chess_widgets-0.5.0-py3-none-any.whl -
Subject digest:
120bbd7516a57736d00a9d27384f0e2b19395c83cc78a2ae71a1f379e746c14c - Sigstore transparency entry: 720811081
- Sigstore integration time:
-
Permalink:
leszekhanusz/chess-widgets@c86b19858814764f99b21adf2fd0739b15a3759d -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/leszekhanusz
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c86b19858814764f99b21adf2fd0739b15a3759d -
Trigger Event:
push
-
Statement type: