Howdy, Stranger!

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

Supported by

Changing image on keypress

Hi,

I am trying to program a test trial where participants can change the image that is displayed on the screen.

To choose the image I would really like for them to scroll through a set of images by pressing a button (e.g. press 'a' to show img_x and press 'l' to show img_y) and then when they decide press 'enter' to move on.

I am trying to do something similar to the BART experiment, i.e. where a participant presses a button such as 'spacebar' and the image increases in size. But instead of increasing in size, during a trial the actual image changes. Once the participant has decided on which image they want, they then press 'enter' and the specific image choice is logged. I have 10 images, named 1.png, 2.png etc.

I know this will require some in-line coding, with if statements, but I just can't figure out how to do it, my programming skills are beginner only.

Any help would be much appreciated!

Thanks,

James

Comments

  • Hi James,

    Sounds like fun. Here my implementation. Let me know if it does what you want.

    import random
    
    cv = canvas() # create an empty canvas
    kb = keyboard(timeout = 20,keylist = ['a','l','return']) # create a keyboard item that allows for 3 different keys
    
    letters = [1,2,3,4,5,6,7,8] # my stimuli, I don't have your images.
    
    random.shuffle(letters) # randomize images
    
    for i in range(len(letters)-1): # loop over each comparison, I don't knwo whether this is what you had in mind, if not you can remove this for loop 
        var.selected_item = None # initliaze the item that will be selected
        while True: # stay in the loop until a selection was done
            cv.text(letters[i],x = -200) # draw one stimulus to a canvas
            cv.text(letters[i+1],x = 200) # draw the other to the canvas
            cv.show() # shwo the canvas
            if var.selected_item == True:
                cv.clear() # clear the canvas, if no selection has been made yet
            k,t=kb.get_key() # sample a key response
            if k == 'a': # if a was pressed (left stimulus)
                cv.clear() # clear the canvas and...
                cv.rect(-250,-50,100,100) # draw a rectangle around the stimulus to mark it as selected
                var.selected_item = letters[i] # store selection in variable
            elif k == 'l': # same for the right stimulus
                cv.clear()
                cv.rect(150,-50,100,100)
                var.selected_item = letters[i+1]
            elif k == 'return': # if return pressed, break the loop and clear the canvas
                cv.clear()
                break
    
    

    I made it with letters because I haven't had images, but it should be doable to adjust. Basically get the path for each image like so: path = exp.pool[u'image_in_pool.png'], and store all the paths in a list. And later draw the images with my_canvas.image(path,x=x) instead of with canvas.text(). See also here: http://osdoc.cogsci.nl/3.1/manual/python/canvas/#function-canvas46image40fname-centertrue-xnone-ynone-scalenone41

    Good luck.

    Eduard

    Buy Me A Coffee

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games