Skip to main content

A pygame menu library

Project description

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

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

pgmenu-1.5.1.tar.gz (59.0 kB view details)

Uploaded Source

Built Distribution

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

pgmenu-1.5.1-py3-none-any.whl (62.4 kB view details)

Uploaded Python 3

File details

Details for the file pgmenu-1.5.1.tar.gz.

File metadata

  • Download URL: pgmenu-1.5.1.tar.gz
  • Upload date:
  • Size: 59.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for pgmenu-1.5.1.tar.gz
Algorithm Hash digest
SHA256 497c26ba1edaae030954adc6b1171a806949ec0583753a19c2c576a72ef4352b
MD5 ac3b4c66609795dbcdb3b2bf9a5c84aa
BLAKE2b-256 e7f541f32cb01d00cb7221ead87dc510bd0078aa7214cd520d09646ff39e7475

See more details on using hashes here.

File details

Details for the file pgmenu-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: pgmenu-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 62.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.7

File hashes

Hashes for pgmenu-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b647320fe9640276f5edb58f42cc0e15fd055741b853866de3d8a4ec36d7495b
MD5 123f6d1f8311ebf8af011ceb384b384f
BLAKE2b-256 555eaf4a0b4a6f892196c3f5e2586acb9c0b7fa7d89b33e2f1b3ca4fc211d898

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