Python GUI library for creating 2D arrays based board games
Project description
game2dboard
A quick and easy way to create board games using 2d arrays in Python. This Python GUI package provides a graphical user interface (GUI) for 2d arrays (matrix).
Installation
Install the latest release by cloning the repository:
git clone https://github.com/mjbrusso/game2dboard.git
cd game2dboard
python3 setup.py install --user
Usage
The API is documented bellow and within the docstrings.
This simple example only provides an overview. See the examples for more details.
Before running, copy this and this files into a img/
folder.
from game2dboard import Board
def mouse_fn(btn, row, col): # mouse calback function
b[row][col] = 1 if not b[row][col] else 0
b = Board(3, 4) # 3 rows, 4 columns, filled w/ None
b[0][0] = 1
b.title = "Click me!"
b.cell_size = 120
b.cell_color = "bisque"
b.on_mouse_click = mouse_fn
b.show()
Galery
Some screenshots from examples.
Memory Game 58 SLOC View source |
Snake 87 SLOC View source |
API
Creation
game2dboard.Board(nrows, ncols)
Creates a Board.nrows
: int – The number of rows.ncols
: int – The number of columns.
Properties
-
size
: int (readonly)
Number of elements in the array -
nrows
: int (readonly)
Number of rows in the array. -
ncols
: int (readonly)
Number of columns in the array. -
title
: str
Gets or sets the window title. -
cursor
: str
Gets or sets the mouse cursor shape.
See avaliable cursor names in https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/cursors.html -
margin
: int
Gets or sets the board margin (px). -
cell_spacing
: int
Gets or sets the space between cells (px). -
margin_color
: str
Gets or sets the margin color. -
cell_color
: str
Gets or sets cells color
See available color names in http://www.science.smith.edu/dftwiki/index.php/Color_Charts_for_TKinter -
grid_color
: str
Gets or sets grid color -
cell_size
: int | (int, int)
Gets or sets the cells dimension (width, height) -
on_key_press
: function(key: str)
Gets or sets the keyboard callback function -
on_mouse_click
: function(button: str, row: int, col: int)
Gets or sets the mouse callback function -
on_timer
: function()
Gets or sets the timer callback function
Methods
-
show()
Create the GUI, display and enter the run loop. -
start_timer(msecs)
Start a periodic timer that executes the a function everymsecs
milliseconds
The callback function must be registered using.on_timer
property.msecs
(int) – Time in milliseconds.
-
stop_timer()
Stops the current timer. -
pause(msecs, change_cursor=True)
Delay the program execution for a given number of milliseconds.
Warning: long pause freezes the GUI!msecs
(int) – Time in milliseconds.change_cursor
(bool) – Change the cursor to “watch” during pause?
-
shuffle()
Random shuffle all values in the board -
fill(value, row=None, col=None)
Fill the board (or a row, or a column) with a valuevalue
– The value to storerow
(int) – Index of row to fill. Default=None
(all rows)col
(int) – Index of column to fill. Default=None
(all columns)
-
clear()
Clear the board, setting all values toNone
. -
close()
Close the board, exiting the program. -
create_output(**kwargs)
Create a output message bar.kwargs
:color
= strbackground_color
= strfont_size
= int
-
print(*objects, sep=' ', end='')
Print message to output bar.
Use like built-inprint()
function.
TO DO
To do.... ;-)
License
game2darray is under MIT license.It can be reused within proprietary software provided that all copies of the licensed software include a copy of the MIT License terms and the copyright notice.
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
Hashes for game2dboard-0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 951f5ce2aa642093d13f3c4e4e3acc6aa7cb1cad6c8353c619878e9e53480ce4 |
|
MD5 | 8be45ec278514fde29782d34370ac14a |
|
BLAKE2b-256 | d31ff5ed669d9f772948e08fa0f2f0650f06d8ea19fe5a5afa9dfce6d9bb8fd9 |