Skip to main content

pgmenu

pgmenu is a basic library for an easy creation of menus in pygame, supporting multiple widget types and designed with the user's experience at heart.

It's optimized to not hinder performance, maintaining above 200 FPS on average and above 100 FPS for big projects. It's also the most customizable possible, allowing for any visuals to be modified to the user's liking. On top of all that, it stays true to the normal pygame experience, using simple and almost identical syntaxes to pygame's, making it easy to just add at any moment into your project.

This library is made for your project, not the project made around the library.

If you have any features or changes to add, or bugs to fix, please contact me at vermylioncode@gmail.com. Thanks in advance!

Quick Guide

A simple and quick guide to read on how to use this fabulous library.

Installation

This library can be installed using PyPI:

pip install pgmenu

Or manually via GitHub or GitLab.

This library uses mainly pygame. On one rare occasion, Pillow, itertools and darkdetect are used.

Usage

This library, like any menu libraries, allow for multiple use case. It can be used for making video game menus, interactable overlay UIs (widgets allow for transparency), or full-blown applications.

Here is a list of the available widgets:

  • pgmenu.Button
  • pgmenu.Checkbox
  • pgmenu.Textbox
  • pgmenu.Frame
  • pgmenu.Text
  • pgmenu.Image

Other main functions:

  • pgmenu.Menu
  • pgmenu.Theme
  • pgmenu.draw()
  • pgmenu.update()
  • pgmenu.getVar()
  • pgmenu.requestCursor()

Example

An example for a simple login screen using pgmenu:

import pygame

import pgmenu

FPS = 60

# Initiating window using pygame
pygame.init()
pygame.display.set_caption('Login Demo')
screen = pygame.display.set_mode((700, 700))
# Filling screen using theme-given background color
screen.fill(pgmenu.getVar('bgColor'))
clock = pygame.time.Clock()

def submit():
    # Check if checkbox of id agreementCheckbox has been checked (aka equal to True)
    if pgmenu.Checkbox.get(agreementCheckbox) == True:
        print('Username:', pgmenu.Textbox.get(usernameTextbox))
        print('Password:', pgmenu.Textbox.get(passwordTextbox))

def checkboxType(id):
    print(pgmenu.Checkbox.get(id))

# pgmenu default mode is 'System' ('System', 'Dark', 'Light')
# pgmenu default theme is Blue ('BLUE', 'RED', 'GREEN', 'YELLOW', 'PURPLE', 'BLUE&BLACK', 'RED&BLACK', 'GREEN&BLACK', 'YELLOW&BLACK', 'PURPLE&BLACK')
## pgmenu.Theme.mode('System')
## pgmenu.Theme.set('BLUE')

# Creating the widgets
loginFrame = pgmenu.Frame.create((100, 100), (500, 500))

loginText = pgmenu.Text.create(screen, 'Login Demo', (250, 20), textSize = 45, centerX = True)

usernameText = pgmenu.Text.create(screen, 'Username', (50, 95), textSize = 25)
usernameTextbox = pgmenu.Textbox.create((50, 125), (400, 40))

passwordText = pgmenu.Text.create(screen, 'Password', (50, 200), textSize = 25)
passwordTextbox = pgmenu.Textbox.create((50, 230), (400, 40))

agreementCheckbox = pgmenu.Checkbox.create((50, 290), activatedFunction = lambda: checkboxType(agreementCheckbox))
submitButton = pgmenu.Button.create((100, 400), (300, 50), activatedFunction = submit)

# Setting the visuals for the widgets
pgmenu.Frame.visuals(screen, loginFrame, borderRadius = 20)

pgmenu.Textbox.visuals(screen, usernameTextbox)
pgmenu.Textbox.visuals(screen, passwordTextbox, textCoverUp = '*')

pgmenu.Checkbox.visuals(screen, agreementCheckbox, text = 'I agree that pgmenu is beautiful', textSize = 20)
pgmenu.Button.visuals(screen, submitButton, text = 'Submit', textSize = 30, borderRadius = 15)

# Adding them to the frame
pgmenu.Frame.add(loginFrame, loginText, usernameText, usernameTextbox, passwordText,
                 passwordTextbox, agreementCheckbox, submitButton)
# Adding them to a menu for easier global manipulation
pgmenu.Menu.add('login', loginFrame, loginText, usernameText, usernameTextbox, passwordText,
                passwordTextbox, agreementCheckbox, submitButton)
pgmenu.Menu.show('login')

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            print('Bye Bye!')
            running = False

    # Refresh screen every frame
    screen.fill(pgmenu.getVar('bgColor'))

    # Draw the widgets (this time not individually, because pgmenu.Menu takes care of it for us)
    # By default, pgmenu.Menu.draw() shows the current shown Menu
    pgmenu.Menu.draw()

    pygame.display.flip()
    # Update the widgets
    pgmenu.update(event)
    # Update clock
    clock.tick(FPS)

Documentation

Documentation is in the works, and will be available in the next release (pgmenu 1.6).

Releases

Next Release (1.6)

  • DOCUMENTATION
  • pgmenu.Surface or pgmenu.Canvas
  • pgmenu.Progressbar
  • Argument: imageSurface
  • Potentially: pgmenu.Slider and pgmenu.Freeslider
  • Potentially: pgmenu.Display

Release 1.5

  • pgmenu.Button
  • pgmenu.Checkbox
  • pgmenu.Textbox
  • pgmenu.Frame
  • pgmenu.Text
  • pgmenu.Image
  • pgmenu.Menu
  • pgmenu.Theme
  • pgmenu.draw()
  • pgmenu.update()
  • pgmenu.getVar()
  • pgmenu.requestCursor()

pgmenu library by Vermylion

MIT License

3.10.9 Python

Metadata

Release files for pgmenu 1.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pgmenu 1.5.1
File Size Uploaded Provenance Actions
pgmenu-1.5.1.tar.gz 59.0 kB Without provenance Details for pgmenu-1.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pgmenu 1.5.1
File Interpreter ABI Platform Actions
pgmenu-1.5.1-py3-none-any.whl Python 3 none any Details for pgmenu-1.5.1-py3-none-any.whl

Total release size: 121.5 kB

Release files / pgmenu-1.5.1.tar.gz

Download URL pgmenu-1.5.1.tar.gz
Size 59.0 kB
Tags Source
SHA-256 checksum
How to use checksums
497c26ba1edaae030954adc6b1171a806949ec0583753a19c2c576a72ef4352b
BLAKE2b-256 checksum
How to use checksums
e7f541f32cb01d00cb7221ead87dc510bd0078aa7214cd520d09646ff39e7475
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Release files / pgmenu-1.5.1-py3-none-any.whl

Download URL pgmenu-1.5.1-py3-none-any.whl
Size 62.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b647320fe9640276f5edb58f42cc0e15fd055741b853866de3d8a4ec36d7495b
BLAKE2b-256 checksum
How to use checksums
555eaf4a0b4a6f892196c3f5e2586acb9c0b7fa7d89b33e2f1b3ca4fc211d898
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Security for pgmenu 1.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page