ThorPy

A GUI library for pygame

Examples - Image buttons

Full code

Here is shown a fast way to create buttons from images. The image used can be different for normal, hover and pressed states. If no image is passed for hover and/or pressed states, the image for normal state will be used by default.

The files used in this example are normal.png, hover.png and pressed.png.


0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
"""Show how to use image to make buttons. Here 2 buttons are created.""" import thorpy, pygame application = thorpy.Application((500,500), "Image buttons") root = "../documentation/examples/" normal, pressed, hover = "normal.png", "pressed.png", "hover.png" button1 = thorpy.make_image_button(root+normal, root+pressed, root+hover, alpha=255, #opaque colorkey=(255,255,255)) #white=transparent #this time a very simple button, with a text (only 1 image) button2 = thorpy.make_image_button(root+hover, colorkey=False, text="Hello") background = thorpy.Background(image=thorpy.style.EXAMPLE_IMG, elements=[button1, button2]) thorpy.store(background) menu = thorpy.Menu(background) menu.play() application.quit()