Working with text
Moving onto the self.do_stroop_trial function, we use the clear_screen function. clear_screen
creates a Surface with the dimensions of self.screen and fills
it in with the color passed. It then returns that Surface.
place_text_image draws text onto the Surface passed, at given offsets relative to the center of the screen.
In the first example, background is passed as the Surface object to be drawn onto. background
was defined earlier with the clear_screen function. The next parameter, word, refers to the text to be written.
The next three values correspond to text size, x offset, and y offsets. The last two values are the color of the text and the color of the background
of the surface the text will be written on. place_text_image makes a call to get_text_image and placing_rect, explained later.
In the self.show_thanks function, we use two more of pypsyexp's functions, get_text_image and placing_rect. get_text_image
renders a font (Arial by default, determined by Pygame), creates a Surface and draws the message onto the Surface. It then
returns that Surface. placing_rect creates a Rect object of the same
dimensions as the Surface passed to it. The Rect also gets positioned relative to the center of the
passed to it. When taken together, get_text_image creates a Surface with text on it, and placing_rect
takes that Surface to create and position a Rect object, that the text Surface
will be placed into. This is reflected in line 163, where text ( the Surface with writing on it)
is placed onto textpos ( Rect object ) and drawn to background (background Surface).
Previous || 1 2 3 4 5 6 7 8 || Next