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
#ThorPy reactions tutorial : step 1
import thorpy, pygame

#constant reaction func : it does not take the event as first argument
def my_const_func_reaction(a, b="I'm b"):
    print("My constant reaction:", "a =", a, ", b =", b)

#We declare a ConstantReaction. Note that we do not filter the event here.
my_reaction = thorpy.ConstantReaction(reacts_to=pygame.MOUSEBUTTONDOWN,
                                      reac_func=my_const_func_reaction,
                                      params={"a" : 12})

application = thorpy.Application(size=(300, 300), caption="Reaction tuto")

ghost = thorpy.Ghost()
button = thorpy.make_button("my button")
background = thorpy.Background(color=(255,255,255), elements=[button, ghost])
background.finish()
background.add_reaction(my_reaction) #add my_reaction to background's reactions

thorpy.store(background)

menu = thorpy.Menu(background) #create a menu for auto events handling
menu.play() #launch the menu

application.quit()