Skip to main content

A GUI module compatible with pygame

Project description


PyGameUi (or pgui) is a Python library for creating simple GUI's in pygame


Use the package manager pip to install PyGameUI.

pip install pgui

You can also install from source this way:

python3 install --user


PyGameUI widgets need a parent class with a screen attribute of type pygame.Surface and an event loop to be used. This is a simple working example:

import pgui
import pygame
import sys


class Main:
    def __init__(self):
        # Create a screen so we can display our widgets
        self.screen = pygame.display.set_mode((600, 600))

        # Create some widgets
        self.entry = pgui.Entry(self, func=self.clear)
        self.button = pgui.Button(self, func=sys.exit)
        self.print_button = pgui.Button(self, func=self.print_text, text="Print")

        # Modify some widget values

        # Move them to the location we want them to be
        self.entry.move(50, 50)
        self.button.move(50, 100)
        self.print_button.move(200, 50)

        # This is optional but we can but the widgets inside a list so we can
        # then iterate through it to update the widgets
        self.widgets = [self.entry, self.button, self.print_button]

    # Define some functions
    def print_text(self):
        # This will print the text typed in the Entry widget

    def clear(self):
        # This will clear the text in the Entry widget

    def update(self):
        self.screen.fill((60, 60, 60))

        # Update each widget
        for w in self.widgets:

        # Update the screen

    # We can use a separate method for event handling
    def events(self):
        for event in pygame.event.get():
        # The loop does not need to have anything in it but we
        # can use it however we want

        # for event in pygame.event.get():
        #     if event.type == pygame.QUIT: # Exit if the window closing button is clicked
        #         raise SystemExit  # This is just the same as sys.exit()
        #     if event.type == pygame.KEYDOWN:
        #         if event.key == pygame.K_ESCAPE: # Exit if the 'Esc' key is pressed
        #             raise SystemExit  # This is just the same as sys.exit()

main = Main()
while True:


You can read the documentation here


This module is still being developed, and it may be unstable or buggy.


You can see the change logs here


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pgui, version 0.0.8.post1
Filename, size File type Python version Upload date Hashes
Filename, size pgui-0.0.8.post1-py3-none-any.whl (19.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pgui-0.0.8.post1.tar.gz (13.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page