Displaying images and monitoring keyboard events
Moving onto the self.do_exp method, we see self.show_instructions which calls three more of pypsyexp's functions:
show_centered_image, update_display, and get_response.
self.show_instructions first calls show_centered_image. The filename parameter refers
to the name of the image file to be displayed.
While images can be directly referenced by using the form self.resources["img_name.type"], show_centered_image takes just the filename.
The second parameter refers to the color of the background the image will be placed on. white was defined earlier in the program, but you
can also pass a three value tuple or list. There is a third optional parameter that will effect the transparency of the background. Values between 0 (transparent)
and 255 (opaque) are accepted. show_centered_image returns a Surface with the given image centered on it.
self.show_instructions also calls update_display on line 80. update_display takes a
Surface and draws it onto the main Surface created by the
Experiment class, self.screen. It then updates the display with the new Surface showing.
get_response monitors keyboard input and Returns the key pressed (alphanumeric only). In the case of letter inputs,
it returns the ASCII code for the capitalized version of the letter. If you press left Shift and the Tilde key (`/~) at the same time, the program exits. Any
data not already placed in self.datafile will be flushed.
show_centered_image actually calls another function, show_image. show_image places the image on a new
Surface with background of bgcolor
at given x and y offsets relative to the center of the screen. So, if you wanted to place an image somewhere other than the center of the screen,
you could call show_image instead and pass different offsets.
Previous || 1 2 3 4 5 6 7 8 || Next