Provides a chess board as a kivy widget.
Project description
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()
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 kivy_chess_board-0.2.1.tar.gz.
File metadata
- Download URL: kivy_chess_board-0.2.1.tar.gz
- Upload date:
- Size: 334.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.22.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b858e9944eb001284b95963ce2addbd1c25714e2f0c628418acddb94449b13a7
|
|
| MD5 |
e9685e21087847825f6ae0aa404f0795
|
|
| BLAKE2b-256 |
b8828e515e2359d05d9f8a7557c0a62b95b55c9de7f6799b25728cae6fcd1e1a
|
File details
Details for the file kivy_chess_board-0.2.1-py3-none-any.whl.
File metadata
- Download URL: kivy_chess_board-0.2.1-py3-none-any.whl
- Upload date:
- Size: 339.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Alpine Linux","version":"3.22.2","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10baf4f48f5d90cd513a20b92231c2bc2db5eee433f5ff7beaa724bf566bca87
|
|
| MD5 |
0c0fcc40219710d39dfc6e5474b6480b
|
|
| BLAKE2b-256 |
3c98cca6535e84c174d76122fee932f5000d8932ec9cfd327ea5ef66075dae63
|