Howdy, Stranger!

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

Supported by

logging name of canvas

Is there a way to access directly the name of the canvas?

I have something like:

NAME = canvas()
path = ...
t =
var.Stim = NAME  #also tried str(NAME)

It logs <openexp._canvas.xpyriment.Xpyriment object at 0x04E7A090>
But i would like to get NAME logged.


  • Hello,

    I do not know it is answer your question but why not doing the inverse?

    x = 'NAME'
    var.Stim = x
    exec("%s = canvas()" % x)
    path = ...
    t =



  • Hi Sylvain,

    thanks for your answer but that does not help.
    My stimuli are first created and put into a list. The list is shuffled. Then i present them in a sequence. I want to log the presented stimulus before each response.

    Usually i made a workaround by this:

    if NAME[i] == 'NAME1':
    elif NAME[i] == 'NAME2':

    This works nicely to log the Stim as a string.
    However, this gets very long if the list includes many canvas.
    I thought is would be much nicer, if there would be a function that draws on the name of the canvas.
    Something like:


    @sebastiaan & @eduard: Is there something like that?

  • Hi,

    In your first example, you're hardcoding the name of Canvas, which is NAME. Hence, you can simply do the following:

    NAME = canvas()
    path = ...
    t =
    var.Stim = 'NAME'

    But I don't think that this is what you have in mind. What do you want to do? Perhaps you can store the Canvas objects in a dict, where the name serves as the key?


  • Hey,

    Or why not just having two lists, the first one with the name of the canvas, and the second with the canvas() themselves? Like:

    from random import shuffle
    name_canvas = list()
    shape_canvas = list()
    index_canvas = range(10)
    for i in range(10):
        c = canvas()
        c.text('blabla' + str(i))
        name_canvas.append('name' + str(i))
    for i in index_canvas:
        var.Stim = name_canvas[i]


  • I also thought about the two lists, but there was the problem with the shuffling.
    Great idea to shuffle i and not the list!

    Nice! Thanks! :)
    OS Team you are the BEST!

Sign In or Register to comment.