Skip to main content

A popup manager for pygame

Project description

Pygame Popup Manager

made-with-python dl-pypi license version

Pygame Popup Manager is a very small engine permitting to easily build all kind of popup in a pygame project.

Here is an example of basic menus that could be created with this manager:

Main menu with side menu

Installation

The most easy way to install this package is to do it with pip:

pip install pygame-popup

Use

First, don't forget to call pygamepopup.init function right after calling pygame.init function.

The whole system is working around the MenuManager class that is the controller of all the popups in background and in foreground.

An unique instance per scene/window has to be created and the pygame screen on which the popups will appear should be provided, like this:

from pygamepopup.menu_manager import MenuManager

menu_manager = MenuManager(screen)

The display, motion and click methods of this class should be called in the application main loop in order to notify the manager of any pygame event.

To open a new popup menu, you should first create it by instanciate the InfoBox class. The components that should be in the menu should be provided. Next, don't forget to call the open_menu method of the menu manager to notify it about the new menu.

For example, the following code will open a popup with a "do-nothing" button and a close button (added by default by the InfoBox)

from pygamepopup.components import Button, InfoBox

my_custom_menu = InfoBox(
    "Title of the Menu",
    [
        Button(
            title="Hello World!",
            callback=lambda: None
        )
    ]
)

menu_manager.open(my_custom_menu)

If you want more code illustrations, check the examples/minimal_main_menu.py module

Customization

The default graphics resources can be easily changed by your own by simply calling certain methods of the configuration module, wherever you want, as can be seen below.

import pygamepopup

pygamepopup.configuration.set_button_background("sprites/inactive_button.png",
                                                "sprites/active_button.png")
pygamepopup.configuration.set_dynamic_button_background("sprites/inactive_button.png",
                                                        "sprites/active_button.png")
pygamepopup.configuration.set_info_box_background("sprites/menu_box.png")

It is also possible to directly provide an asset to a specific component, if you want a button to be different from others for example.

Button(
    title="Hello World!",
    callback=lambda: None,
    sprite=pygame.image.load("sprites/different_button.png"),
    sprite_hover=pygame.image.load("sprites/different_button_hover.png")
)

With this kind of configuration you can made an interface similar to this one:

Options menu with assets

Contact

You can contact me directly by e-mail if you have any question regarding the package. Also, I will be really happy to know you are using this package, so don't hesitate to share me the link to your project if you tried something!

For suggestions or bugs, please create an issue in the GitHub repository: https://github.com/Grimmys/pygame_popup_manager/issues

Thanks!

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

pygame-popup-0.3.3.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

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

pygame_popup-0.3.3-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file pygame-popup-0.3.3.tar.gz.

File metadata

  • Download URL: pygame-popup-0.3.3.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for pygame-popup-0.3.3.tar.gz
Algorithm Hash digest
SHA256 b614aa1033458f20c45bff9222a7a9b2cd2c2eb3922cb2ef892e0ce02c9e576f
MD5 dcab8aadab09c5871ea6b2fb17584c1a
BLAKE2b-256 c9ddc73ab085e77a14c59bd7b1dfad92d27b4b5b6f70ac53e43ed01fa8ef5c52

See more details on using hashes here.

File details

Details for the file pygame_popup-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: pygame_popup-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

File hashes

Hashes for pygame_popup-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4a795d51857f03286ce1296ecb59f1aaf6fefcfe27bc39336dcbada9837ce879
MD5 4b4d3e756cb34526e21353c2d35f0728
BLAKE2b-256 96809a242fb82ef88110592cff119e99ed1cdbea79288ad6beccbdbba3a909c0

See more details on using hashes here.

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