Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[closed] using python variables as arguments in the draw image function

edited September 2013 in OpenSesame

Hi. I have a string array, and I wanna use its content as a partial path for the draw image function. I know how to do it with opensesame variable (using brackets), but how do I do it with python variables?

Thanks!

Comments

  • edited 2:50AM

    In inline_script items, you use the functions self.get() and exp.set() to get and set variables respectively. This is described here:

    For example, let's say that you have a variable img with the value 'smiley', and a file called smiley.png in the file pool. You can then show smiley.png with the following script:

    from openexp.canvas import canvas
    my_canvas = canvas(exp) # Create canvas
    img = self.get('img') # Get the variable, like [img] in the GUI
    img_path = exp.get_file('%s.png' % img) # Get the full path to the image
    my_canvas.image(img_path) # Draw the image on the canvas
    my_canvas.show() # Show the canvas
    

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

Sign In or Register to comment.