Package psychopy :: Module visual :: Class TextStim
[frames] | no frames]

Class TextStim

source code


Class of text stimuli to be displayed in a :class:`~psychopy.visual.Window`
    

Instance Methods
 
__init__(self, win, text='Hello World', font='', pos=(0.0, 0.0), depth=0, rgb=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, units='', ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz='center', alignVert='center', fontFiles=[], wrapWidth=None)
:Parameters: win: A :class:`Window` object.
source code
 
setHeight(self, height)
Set the height of the letters (including the entire box that surrounds the letters in the font).
source code
 
setFont(self, font)
Set the font to be used for text rendering.
source code
 
setText(self, value=None)
Set the text to be rendered using the current font
source code
 
setRGB(self, value, operation='')
DEPRECATED since v1.60.05: Please use setColor
source code
 
setColor(self, color, colorSpace=None, operation='')
Set the color of the stimulus.
source code
 
draw(self, win=None)
Draw the stimulus in its relevant window.
source code
 
setUseShaders(self, val=True)
Set this stimulus to use shaders if possible.
source code

Inherited from _BaseVisualStim: setContr, setDKL, setDepth, setLMS, setOpacity, setOri, setPos, setSize

Method Details

__init__(self, win, text='Hello World', font='', pos=(0.0, 0.0), depth=0, rgb=None, color=(1.0, 1.0, 1.0), colorSpace='rgb', opacity=1.0, units='', ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz='center', alignVert='center', fontFiles=[], wrapWidth=None)
(Constructor)

source code 

:Parameters:        
    win: A :class:`Window` object. 
        Required - the stimulus must know where to draw itself
    text: 
        The text to be rendered
    pos: 
        Position on the screen            
    depth: 
        Depth on the screen (if None it will be defined on .draw() to be in front of the last object drawn)
    color: 
        The color of the text (ranging [-1,-1,-1] to [1,1,1])
        NB: parameter rgb=() is deprecated.  
    colorSpace: 'rgb'
        The color-space to use.
    opacity: 
        How transparent the object will be (0 for transparent, 1 for opaque)
    units : **None**, 'norm', 'cm', 'deg' or 'pix'  
        If None then the current units of the :class:`~psychopy.visual.Window` will be used. 
        See :ref:`units` for explanation of other options.      
    ori: 
        Orientation of the text            
    height: 
        Height of the characters (including the ascent of the letter and the descent)            
    antialias: 
        boolean to allow (or not) antialiasing the text            
    bold: 
        Make the text bold (better to use a bold font name)            
    italic: 
        Make the text italic (better to use an actual italic font)            
    alignHoriz: 
        The horizontal alignment ('left', 'right' or 'center')            
    alignVert: 
        The vertical alignment ('top', 'bottom' or 'center')            
    fontFiles: 
        A list of additional files if the font is not in the standard system location (include the full path)
    wrapWidth: 
        The width the text should run before wrapping

Overrides: _BaseVisualStim.__init__

setHeight(self, height)

source code 
Set the height of the letters (including the entire box that surrounds the letters in the font). The width of the letters is then defined by the font.

setFont(self, font)

source code 
Set the font to be used for text rendering. font should be a string specifying the name of the font (in system resources)

setRGB(self, value, operation='')

source code 
DEPRECATED since v1.60.05: Please use setColor
Overrides: _BaseVisualStim.setRGB
(inherited documentation)

setColor(self, color, colorSpace=None, operation='')

source code 
Set the color of the stimulus. See :ref:`colorspaces` for further information
about the various ways to specify colors and their various implications.

:Parameters:

color :
    Can be specified in one of many ways. If a string is given then it
    is interpreted as the name of the color. Any of the standard html/X11
    `color names <http://www.w3schools.com/html/html_colornames.asp>` 
    can be used. e.g.::
        
        myStim.setColor('white')
        myStim.setColor('RoyalBlue')#(the case is actually ignored)
    
    A hex value can be provided, also formatted as with web colors. This can be
    provided as a string that begins with # (not using python's usual 0x000000 format)::
        
        myStim.setColor('#DDA0DD')#DDA0DD is hexadecimal for plum
        
    You can also provide a triplet of values, which refer to the coordinates
    in one of the :ref:`colorspaces`. If no color space is specified then the color 
    space most recently used for this stimulus is used again.
    
        myStim.setColor([1.0,-1.0,-1.0], 'rgb')#a red color in rgb space
        myStim.setColor([0.0,45.0,1.0], 'dkl') #DKL space with elev=0, azimuth=45
        myStim.setColor([0,0,255], 'rgb255') #a blue stimulus using rgb255 space
    
    Lastly, a single number can be provided, x, which is equivalent to providing
    [x,x,x]. 
    
        myStim.setColor(255, 'rgb255') #all guns o max
    
colorSpace : string or None

    defining which of the :ref:`colorspaces` to use. For strings and hex
    values this is not needed. If None the default colorSpace for the stimulus is
    used (defined during initialisation). 
    
operation : one of '+','-','*','/', or '' for no operation (simply replace value)
    
    for colors specified as a triplet of values (or single intensity value)
    the new value will perform this operation on the previous color
    
        thisStim.setColor([1,1,1],'rgb255','+')#increment all guns by 1 value
        thisStim.setColor(-1, 'rgb', '*') #multiply the color by -1 (which in this space inverts the contrast)
        thisStim.setColor([10,0,0], 'dkl', '+')#raise the elevation from the isoluminant plane by 10 deg

Overrides: _BaseVisualStim.setColor

draw(self, win=None)

source code 

Draw the stimulus in its relevant window. You must call this method after every MyWin.flip() if you want the stimulus to appear on that frame and then update the screen again.

If win is specified then override the normal window of this stimulus.

Overrides: _BaseVisualStim.draw

setUseShaders(self, val=True)

source code 
Set this stimulus to use shaders if possible.
Overrides: _BaseVisualStim.setUseShaders