Howdy, Stranger!

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

Supported by

canvas question

Hey guys,
I need some ideas on how to implement something that seems easy but yet eludes me. Basically, I want to show a map and when people click on a location to save its pixel coordinates. I've done the click and save part by recycling some code from another example and drawing a fixation point on the mouse location on the canvas (see attachment). The problem is that when I add the png for the map in the while loop that controls the mouse, things slow down a lot. This is of course to be expected as the png gets redrawn on the canvas all the time, but how should I do this instead? Basically, I want to display the map once and redraw the mouse continuously. I tried putting the map outside of the loop but I haven't manged to make the mouse update as it should. Any ideas?
Thanks in advance,


  • Hi Marios,

    First thought: Why don't you simply let the operating system draw the mouse cursor?


    That way you don't have to redraw the canvas over and over again. But if, for whatever reason, that is not an option, there are a few other things you could try to improve performance:

    • Set the timeout to 0, instead of 20
    • Change the backend to legacy, which is faster when it comes to stimulus rendering


  • Thanks Sebastiaan! Initially I was thinking of doing mouse tracking so I went down this route. But, if I decide against it then I could just have the os draw the mouse. Good point. I'll also try the other things you suggested and see what happens. :)

  • Hi Sebastiaan,
    I finally found some time to get back to this and still I cant figure it out. I moved the canvas functions out of the loop and let the OS control the mouse. But, for some reason I can't get a mouse cursor that can be freely moved by the user. Any idea what I'm doing wrong again? I attach my inline.

  • But, for some reason I can't get a mouse cursor that can be freely moved by the user.

    But what happens then? Is the mouse cursor invisible, or is it visible but for some reason unmovable?

  • As is, the mouse only shows up for a bit in thr center of the screen. Playing around with code (if I remember correctly, by changing the timeout value), Igot it to show up for longer but when I was moving it away from the center it kept pushing back to it.By the way, I dont think I understand what timeout really does!

  • Hi Mario,

    Try this code, it works quite nicely for me.

    ms = mouse() cv = canvas() path = exp.pool[u'yourFile.png'] cv.image(path) ms.show_cursor(True) for i in range(6): # I made a loop around the main function to see how it works for multiple mouse clicks while True: # showing the canvas in the beginning of the loop improves the quality a lot! button, position, timestamp = ms.get_click(timeout=0) if button is not None: cv.fixdot(x=position[0],y=position[1],color='red') # fixation marks the click var.lloc_clicked = position var.x=position[0],var.y=position[1] break log.write_vars()

    By the way, I dont think I understand what timeout really does!

    Timeout indicates how long the computer waits before continuing with the script. So a timeout of 20 means that for 20ms the experiment is idle while waiting for the mouse click. A timeout of 0 means, that it does not wait at all (But in that case the function is still responsive for pending clicks, so if you click a mouse button, the click will be registered on the next iteration).

    Hope this helps,.


    Buy Me A Coffee

  • Perfect! Thank you so much for your help Eduard! I'll test the code later today and adapt for my purpose.

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 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