Howdy, Stranger!

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

Supported by

Add button to slider on canvas

edited May 2023 in OpenSesame

Hi,

I added a slider to a canvas. Now i want to add a button in the center of my canvas just below the slider.

I want my participants to either set the slider to a specific position or press the button. The button should be labeled "no answer".


My inline script is as follows:

my_canvas = canvas()
my_mouse = mouse(timeout=20)

# Set slider dimensions. This assumes that 0,0 is the display center, which is
# the default in OpenSesame >= 3.
slider_w = 500
slider_h = 10
slider_x = -slider_w/2
slider_y = -slider_h/2

while True:

    # Determine the slider fill based on the mouse position
    pos, time = my_mouse.get_pos()
    x, y = pos
    slider_fill = min(slider_w, max(0, x-slider_x))

    my_canvas.clear()
    # Draw some text (this can be anything)
    my_canvas.text("angewidert", y=slider_y-100) 
    my_canvas.text("nicht verstanden", y=slider_y+100) 
    my_canvas.text("extrem intensiv", x=slider_x+600)
    my_canvas.text("überhaupt nicht intensiv", x=slider_x-100)
    # Draw the slider frame
    my_canvas.rect(slider_x, slider_y, slider_w, slider_h)
    # Draw the slider fill
    my_canvas.rect(slider_x, slider_y, slider_fill, slider_h, fill=True)                
    # Draw the mouse cursor
    my_canvas.arrow(x+5, y+10, x, y)
    my_canvas.show()

    # Poll the mouse for buttonclicks
    button, position, timestamp = my_mouse.get_click()
    if button is not None:
        break

# Set the slider response as an experimental variable
var.slider_percent = 100.0*slider_fill/slider_w   


Can you help? Thank youuuu

Comments

  • Hi @mirix ,

    Right now you're using a Canvas to draw a custom slider instead of a Form . That's a perfectly acceptable approach, but this means that you have to render everything using the Canvas , including the ok button. (You cannot use any of the predefined form widgets.) The script below is slightly modified from your own script and shows how you can do this. There are three major changes:

    • The Canvas is not cleared before each update. Rather, the slider fill is given a name and then updated selectively while the other elements are left unchanged.
    • A button-like rectangle with the name ok_button is added
    • The loop exists whenever a mouse is clicked inside the ok_button element.

    See also:

    Do you see the logic?

    — Sebastiaan

    my_canvas = Canvas()
    my_mouse = Mouse(timeout=20, visible=True)
    my_mouse.show_cursor()
    
    # Set slider dimensions. This assumes that 0,0 is the display center, which is
    # the default in OpenSesame >= 3.
    slider_w = 500
    slider_h = 10
    slider_x = -slider_w/2
    slider_y = -slider_h/2
    
    # Draw some text (this can be anything)
    my_canvas.text("angewidert", y=slider_y-100) 
    my_canvas.text("nicht verstanden", y=slider_y+100) 
    my_canvas.text("extrem intensiv", x=slider_x+600)
    my_canvas.text("überhaupt nicht intensiv", x=slider_x-100)
    # Draw the ok button. We give the frame a name so that we can
    # use this name later to check whether the button was clicked
    my_canvas['ok_button'] = Rect(x=-100, y=200, w=200, h=50)
    my_canvas.text(x=0, y=225, text='acceptieren')
    # Draw the slider frame
    my_canvas.rect(slider_x, slider_y, slider_w, slider_h)
    # Draw the slider fill. We give the fill rectangle a name so
    # that we can change its width later
    my_canvas['slider'] = Rect(slider_x, slider_y, slider_w, slider_h, fill=True)                
    
    while True:
        # Determine the slider fill based on the mouse position
        pos, time = my_mouse.get_pos()
        x, y = pos
        slider_fill = min(slider_w, max(0, x-slider_x))
        my_canvas['slider'].w = slider_fill
        my_canvas.show()
        # Poll the mouse for buttonclicks
        button, position, timestamp = my_mouse.get_click()
        if button is not None and position in my_canvas['ok_button']:
            break
    
    # Set the slider response as an experimental variable
    var.slider_percent = 100.0*slider_fill/slider_w   
    


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