ThorPy

A GUI library for pygame

Examples - Exclusion Pools

Full code

The code below shows how to set up radio buttons so that there is always only one that is selected. Also, togglable buttons are defined, which behave the same way, except that we allow them to be all unselected.

 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
import thorpy

ap = thorpy.Application((300,300))

#format of a Pool : thorpy.Pool(elements, first_value, always_value)
#   <first_value> can be None, and is the element that is 'on' at the beginning
#   <always_value>=True means that there must always be an element which is 'on'

#make radios
radios = [thorpy.Checker.make("radio"+str(i), type_="radio") for i in range(4)]
radio_pool = thorpy.RadioPool(radios, first_value=radios[2], always_value=True)

#make togglable buttons
buttons = [thorpy.Togglable.make("togglable"+str(i)) for i in range(4)]
togglable_pool = thorpy.TogglablePool(buttons, first_value=buttons[1],
                                                        always_value=False)

#cosmetic separation line
line = thorpy.Line.make(200, "h")

bck = thorpy.Background.make((220,220,255), elements=radios+[line]+buttons)
thorpy.store(bck)
menu = thorpy.Menu(bck)
menu.play()
ap.quit()