glooey
— An object-oriented GUI library for pyglet
Every game needs a user interface that matches its look and feel. The purpose
of glooey
is to help you make such an interface. Towards this end,
glooey
provides 7 powerful placement widgets, a label widget, an image
widget, 3 different button widgets, a text entry widget, a variety of scroll
boxes and bars, 4 different dialog box widgets, and a variety of other
miscellaneous widgets. The appearance of any widget can be trivially
customized, and glooey
comes with built-in fantasy, puzzle, and 8-bit
themes to prove it (and to help you hit the ground running if your game fits
one of those genres).
The philosophy behind glooey
is that deriving subclasses from a basic set
of widgets with no default style is the most elegant way to control how widgets
look. This approach is flexible because subclasses can customize or override
most aspects of the basic widgets. But it's also surprisingly succinct and
powerful: specifying a style is usually as simple as setting a class variable,
and styles can be easily composed using either inner classes or previously
defined widgets. This philosophy makes glooey
easy to get started with,
and powerful enough to support even the most complicated games.
.. image:: https://img.shields.io/pypi/v/glooey.svg :target: https://pypi.python.org/pypi/glooey .. image:: https://img.shields.io/pypi/pyversions/glooey.svg :target: https://pypi.python.org/pypi/glooey .. image:: https://img.shields.io/github/workflow/status/kxgames/glooey/Test%20and%20release/master :target: https://github.com/kxgames/glooey/actions .. image:: https://img.shields.io/readthedocs/glooey.svg :target: https://glooey.readthedocs.io/en/latest/?badge=latest
The documentation <https://glooey.readthedocs.io/en/latest/>
_ thoroughly explains what glooey
can do and how to use it,
but here's a quick example to give a feel for what it looks like in action::
$ pip3 install glooey
.. code-block:: python
import pyglet import glooey
class MyLabel(glooey.Label): custom_color = '#babdb6' custom_font_size = 10 custom_alignment = 'center'
class MyTitle(glooey.Label): custom_color = '#eeeeec' custom_font_size = 12 custom_alignment = 'center' custom_bold = True
class MyButton(glooey.Button): Foreground = MyLabel custom_alignment = 'fill'
# More often you'd specify images for the different rollover states, but
# we're just using colors here so you won't have to download any files
# if you want to run this code.
class Base(glooey.Background):
custom_color = '#204a87'
class Over(glooey.Background):
custom_color = '#3465a4'
class Down(glooey.Background):
custom_color = '#729fcff'
# Beyond just setting class variables in our widget subclasses, we can
# also implement new functionality. Here we just print a programmed
# response when the button is clicked.
def __init__(self, text, response):
super().__init__(text)
self.response = response
def on_click(self, widget):
print(self.response)
window = pyglet.window.Window()
gui = glooey.Gui(window)
vbox = glooey.VBox() vbox.alignment = 'center'
title = MyTitle("What...is your favorite color?") vbox.add(title)
buttons = [ MyButton("Blue.", "Right, off you go."), MyButton("Blue. No yel--", "Auuuuuuuugh!"), MyButton("I don't know that!", "Auuuuuuuugh!"), ] for button in buttons: vbox.add(button)
gui.add(vbox)
pyglet.app.run()