A GUI library for pygame

User Guide - Cheat Sheet

List of ThorPy elements - List of ThorPy events - List of style methods

List of ThorPy elements

Here are summarized the available built-in elements in ThorPy. We provide some examples pointing out specificities of the elements that can be given during initialization. This does not embrace all the parameters of the different elements. Finally, many composite elements are available, such as alerts, dialog and choice boxes, image buttons, ... You can find them on the examples page.

As a user, remember that the wrappers thorpy.make_button("my button", my_function) and thorpy.make_text("my text") most of the time do the job for planty of functionalities.

AnimatedGif: read and play an animated gif.
Example: AnimatedGif("path/to/myGif")
Full prototype: AnimatedGif(path, colorkey=None, low=2, nread=float("inf"))

Background: define a background for another element or menu.
Example: Background(color=(255,255,255))
Example: Background(image="path/to/myImage", elements=some_elements)
Full prototype: Background(color=None, image=None, elements=None, mode="scale to screen")

Box: box containing other elements
Example: Box(elements=some_elements)
Full prototype: Box(elements, size=None)

Browser: file and folder browser
Example: Browser(path="/my/path/"), Browser.make"./", folders=False, file_types=(".txt", ".png"))
Full prototype: Browser(path="./", ddl_size=None, folders=True, files=True, file_types=None, text="")

BrowserLauncher: button for launching a file browser
Example: BrowserLauncher(a_browser, "Choose a file")
Full prototype: BrowserLauncher(browser, const_text="", var_text="", show_select=True, click_cancel=False, text_ok="Ok", text_cancel="Cancel", size=style.MAKE_SIZE)

BrowserLight: file and folder browser restricted to a given directory
Example: BrowserLight(path="/my/path/"), BrowserLight("./", folders=False, file_types=(".txt", ".png"))
Full prototype: BrowserLight(path="./", ddl_size=None, folders=True, files=True, file_types=None, text="")

Checker: check or radio box
Example: Checker("Do you like potatoes?", value=True), Checker("my radio", typ="radio")
Full prototype: Checker(text="", value=False, type_="checkbox")

Clickable: pressable and hoverable element
Example: Clickable("hello")
Full prototype: Clickable(text="", elements=None, size=style.MAKE_SIZE)

ClickDraggable: togglable clickable that can be dragged/dropped according to its state pressed/unpressed
Example: ClickDraggable("hello")
Full prototype: ClickDraggable(text="", elements=None, size=style.MAKE_SIZE)

ColorSetter: box in which three sliders and a visualization square provide a way to define a color
Example: ColorSetter("Choose a color", value=(255, 0, 0))
Full prototype: ColorSetter(text="", elements=None, size=None, color_size=(50, 50), value=(255, 0, 0))

ColorSetterLauncher: button for launching a ColorSetter instance
Example: ColorSetterLauncher(aColorSetter, text="Choose color", show_select=True, click_cancel=False)
Full prototype: ColorSetterLauncher(colorsetter, text="", show_select=True, click_cancel=False)

Draggable: clickable that can be dragged/dropped
Example: Draggable("hello")
Full prototype: Draggable(text="", elements=None, size=style.MAKE_SIZE)

DropDownList: vertical list of multiple texts that can be selected
Example: DropDownList(titles=["proposition1", "prop2", "prop3"])
Full prototype: DropDownList(titles, size="auto", heavy=False, folders=None, margins=None, x=None)

DropDownListLauncher: button for launching a drop down list
Example: DropDownListLauncher(const_text="Choose", titles=list_of_titles)
Full prototype: DropDownListLauncher(const_text="", var_text="", titles=None, ddlf_size="auto", show_select=True, click_cancel=True, size=style.MAKE_SIZE)

DynamicShadow: shadow that changes when linked element changes
Shadows are highly parametrizable. They do not provide a make initializer (thus you must call finish method!). Please refer to this simple example.
Example: DynamicShadow(target=an_element)

Element: most simple graphical element
Example: Element(text="hello"), Element("hello", elements=some_children)
Full prototype: Element(text="", elements=None, size=style.MAKE_SIZE)

Ghost: non-graphical element
Example: Ghost(), Ghost(elements=some_children)
Full prototype: Ghost(elements=None)

Hoverable: hoverable element (reacts on mouse hover)
Example: Hoverable("hello")
Full prototype: Hoverable(text="", elements=None, size=style.MAKE_SIZE)

HoverZone: ghost element that can post hover events
Example: HoverZone(pygame.Rect(100,50,200,200)), HoverZone(some_element.get_rect())
Full prototype: HoverZone(zone=None, elements=None)

Image: image element
Example: Image(path="path/to/an/image")
Full prototype: Image(path=None, color=None)

Inserter: element for text insertion
Example: Inserter(name="Write here:", value="just here")
Full prototype: Inserter(name="", elements=None, value="", size=(None, None))

KeyPressable: element that is pressed when a key is pressed
Example: KeyPressable(key=pygame.K_t, text="hello")
Full prototype: KeyPressable(text="", elements=None, size=style.MAKE_SIZE)

KeyTogglable: element that toggles according to a key press
Example: KeyTogglable(key=pygame.K_t, text="hello")
Full prototype: KeyTogglable(text="", elements=None, size=style.MAKE_SIZE)

LifeBar: allows for the representation of a life bar or progress bar
Example: LifeBar("Remaining time")
Full prototype: LifeBar(text="", color=(255,165,0), text_color=(0,0,0), size=(200,30), font_size=None, type_="h")

Line: separation line
Example: Line(size=100, type_="horizontal")
Full prototype: Line(size, type_, color=None, pressed=True)

MultilineText: pure text on multiple lines (of course can be only 1 line)
Example: MultilineText(text="1st line!\n2nd line...", size=(100,100))
Full prototype: MultilineText(text="", elements=None, size=style.MAKE_SIZE)

OneLineText: pure text on only one line
Example: OneLineText("hello")
Full prototype: OneLineText(text="", elements=None, size=style.MAKE_SIZE)

ParamSetter: Put automatically defined elements in a box, in order to set variables.
Example: ParamSetter(varsets=a_varset)(see game examples)
Full prototype: ParamSetter(varsets, elements=None, size=None)

ParamSetterLauncher: Button that launch a ParamSetter.
Example: ParamSetterLauncher(varsets=varset_list_or_paramsetter)(see game examples)
Full prototype: ParamSetterLauncher(params, text="", title=None, click_cancel=False, text_ok="Ok", text_cancel="Cancel", paramsetter_elements=None, size=style.MAKE_SIZE)

Pressable: element that can be pressed/unpressed (with mouse by default)
Example: Pressable("hello")
Full prototype: Pressable(text="", elements=None, size=style.MAKE_SIZE)

SliderX: slider for choosing a value
Example: SliderX(length=100, limvals=(4, 12), text="hello", initial_value=10, typ=float)
Full prototype: SliderX(length, limvals=None, text="", type_=float, initial_value=None)

StaticShadow: shadow that follows its target element
Shadows are highly parametrizable. They do not provide a make initializer (thus you must call finish method!). Please refer to this simple example.
Example: StaticShadow(target_element=an_element)

Togglable: element that can be toggled by mouse
Example: Togglable("hello")
Full prototype: Togglable(text="", elements=None, size=style.MAKE_SIZE)

List of ThorPy events

Here are summarized the id attribute of events automatically posted by built-in ThorPy elements. They are all stored in thorpy.constants module. They are all regrouped under the pygame event whose type is thorpy.constants.THORPY_EVENT (see this important note on thorpy events). We summarize below the thorpy events avalaible, giving for each of them the constant name corresponding to their id attribute. With each event are listed its other attributes.

A tutorial on reactions can be found here.

Id Description Attributes
EVENT_CANCEL Posted when a cancel button from a box has been clicked el: element canceled
EVENT_CHANGE_STATE Posted when the state of an element has been changed el: concerned element
EVENT_DDL Posted when a string has been selected in a Drop Down List. Can be posted by a DropDownList or a DropDownListLauncher. el: DropDownList element; value: selected text
EVENT_DONE Posted when a button for validating something has been clicked el: concerned element
EVENT_DRAG Posted each time an element is dragged el: dragged element
EVENT_HOVER Posted when an hoverable element is hovered el: hovered element
EVENT_INSERT Posted when a text has been inserted (and validated) el: inserter element; value: inserted text
EVENT_LAUNCH Posted when an element has been dynamically launched in a menu el: launched element
EVENT_PRESS Posted when an element has been pressed (i.e it enters the state 'pressed') el: pressed element
EVENT_SLIDE Posted when a slider's dragger has been slided el: slider element
EVENT_TIME Posted by the menu, except if it is a thorpy.BasicMenu instance. The menu tries to post this event at each frame (so if your menu has attribute fps = 60, you can expect this event to occur 60 times per second tick: the number of milliseconds passed between the previous two frames of the menu
EVENT_UNPRESS Posted when an element has been unpressed el: unpressed element
EVENT_UNLAUNCH Posted when an element has been dynamically removed from a menu el: concerned element
EVENT_WHEEL Posted when mousewheel has been used on an element that handles it el: concerned element

List of ThorPy basic styling methods

The following methods can be used on all graphical elements for basic styling changes. Also, consider using thorpy.set_theme function if you plan to change the style of a whole group of elements (example: thorpy.set_theme('human')). Moreover, you are free to redefine all the graphical default values contained into (example: = (20,10) will change the default x-y margins for all the next elements initialized). Finally, the tutorial section contains a tutorial about defining your own design template.

set_size(new_size): resize the element. The new size is a tuple whose elements can be None: in this case, the resizing doesn't occur on the corresponding axis.

scale_to_title(): resize the element so that it fits its textual content. You can optionally pass a tuple as argument, indicating the margins (otherwise the default margins are used).

set_main_color(new_color): change the element's main color. The color can be in the format (R,G,B) or (R,G,B,A). The element's painter determines how this influe the appearance.

set_font(new_font): change the font of the element's text. If the font cannot be found in your system, then this instruction is ignored.

set_font_color(color): change the color of the font.

set_font_size(size): change the font size. The size is a integer corresponding to the size of the font in pts (typical value: 12)

set_font_color_hover(color): change the color of the font when hovered, for hoverable elements.