Skip to main content

A Python PyGame package extension

Project description

pgex

A Python PyGame package extension.

Desription

Pgex is a package that will help you to create games with PyGame easier and more convenient. There is no longer any need to register the functionality of text fields, buttons and other widgets each time. Everything has already been done for you!

Installation

Package is uploaded on PyPI and can be downloaded through

pip install pgex

Links

Link on PyPI: https://pypi.org/project/pgex/
GitHub Repository: https://github.com/IvanFoke/pgex

Usage

1. Text creation
Before you start creating any project on PyGame, you must initialize it. Use standard commands like screen creation and title setting.
All widgets in pgex are stored in pgex.widgets. For example, let's import Text widget. Pgex also describes a large number of different colors. They can be found in pgex.parameters.

import pygame as pg
from pgex.widgets import Text
from pgex.parameters import colors

pg.init()
screen = pg.display.set_mode((800, 600))
pg.display.set_caption("Pgex Example")
clock = pg.time.Clock()

txt = Text("SomeText", r'Crushez.ttf', 100, font_color=colors["dark_gray"], bg_color=colors["white"], border_width=1)

game = True
while game:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            game = False
            break
    screen.fill(colors["light_blue"])
    txt.draw(screen, (100, 300))
    pg.display.update()
    clock.tick(30)

As you can see in the example, text widget is created with Text class. First 3 arguments are the text, the path to a font and the font size. Result of the work of this program:

python_RdNLxTmrXB

2. A Button that gets a value of an Entry field
Button and Entry are another widgets from pgex. They also can be imported from pgex.widgets.
A distinctive feature of the Button is the passing of a function into it through the action argument, which will be called when the user clicks on it.
The Entry requires the passing of PyGame events. This allows widget to intercept the data entered in the field. Field supports backspace key. To stop entering the text in field, you can press escape, enter, or simply click the left mouse button outside the field.

from pgex.widgets import Button
from pgex.widgets import Entry


def get_entry_value():
    global entry
    print(f"Got text: {entry.text}")


entry = Entry(200, 50, r'Crushez.ttf', 20, centralized=True)
btn = Button(200, 100, "Btn", r'Crushez.ttf', 40, r'button.wav', action=get_entry_value, centralized=True)

def handle_events(events):
    for event in events:
        if event.type == pg.QUIT:
            return False
    return True

# ... in game cycle
while True:
    # ...
    events = pg.event.get()
    if not handle_events(events):
        break
    btn.draw(screen, (500, 100))
    entry.draw(screen, (100, 200), events)      

Result:
python_cr2iYoWarZ

Full example can be seen in examples folder.
All other possibilities will be described soon.

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

pgex-0.4.4.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

pgex-0.4.4-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file pgex-0.4.4.tar.gz.

File metadata

  • Download URL: pgex-0.4.4.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pgex-0.4.4.tar.gz
Algorithm Hash digest
SHA256 b53ffb0e1a6a792e6f9db1ee717108b2b42d39b4ae37089d321c5d9bf0ce8629
MD5 98b8c6f25f87ef66fecb37710cf9a50d
BLAKE2b-256 f68bb20c3efa0ed852aef653d9f1f92095a43528971e05efe7ca0802dfa823b8

See more details on using hashes here.

File details

Details for the file pgex-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: pgex-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for pgex-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 df657d694c2da849030bbaafb3b0f4559d00be88a74e92b34a75a3cb0ef5e1ca
MD5 0ad3a5232a673eb096493f5ebab4376e
BLAKE2b-256 fde706d91d18d634e362e42b753bb79334f167c9ed5d32b0c5178704c82204ec

See more details on using hashes here.

Supported by

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