ThorPy

A GUI library for pygame

Examples - Menu and submenus

Full code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import thorpy

#Declaration of the application in which the menu is going to live.
application = thorpy.Application(size=(500, 500), caption='ThorPy stupid Example')

#Setting the graphical theme. By default, it is 'classic' (windows98-like).
thorpy.theme.set_theme('human')

#Declaration of some elements...
useless1 = thorpy.Element.make("This button is useless.\nAnd you can't click it.")

text = "This button also is useless.\nBut you can click it anyway."
useless2 = thorpy.Clickable.make(text)

draggable = thorpy.Draggable.make("Drag me!")

box1 = thorpy.make_ok_box([useless1, useless2, draggable])
options1 = thorpy.make_button("Some useless things...")
thorpy.set_launcher(options1, box1)


inserter = thorpy.Inserter.make(name="Tip text: ",
                                value="This is a default text.",
                                size=(150, 20))

file_browser = thorpy.Browser.make(path="C:/Users/", text="Please have a look.")

browser_launcher = thorpy.BrowserLauncher.make(browser=file_browser,
                                                const_text="Choose a file: ",
                                                var_text="")

color_setter = thorpy.ColorSetter.make()
color_launcher = thorpy.ColorSetterLauncher.make(color_setter,
                                                    "Launch color setter")

options2 = thorpy.make_button("Useful things")
box2 = thorpy.make_ok_box([inserter, color_launcher, browser_launcher])
thorpy.set_launcher(options2, box2)

quit_button = thorpy.make_button("Quit")
quit_button.set_as_exiter()

central_box = thorpy.Box.make([options1, options2, quit_button])
central_box.set_main_color((200, 200, 200, 120))
central_box.center()

#Declaration of a background element - include your own path!
background = thorpy.Background.make(image=thorpy.style.EXAMPLE_IMG,
                                    elements=[central_box])

menu = thorpy.Menu(elements=background, fps=45)
menu.play()

application.quit()