# Mouse.py in demos giving TypeError: unsupported operand type(s) for /: 'tuple' and 'int'

**URL:** <https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112>\
**Category:** Coding\
**Created:** [September 25, 2017, 8:49pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112 "2017-09-25T20:49:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Iva28](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iva28](https://discourse.psychopy.org/u/Iva28)\
**Post date:** [September 25, 2017, 8:49pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/1 "2017-09-25T20:49:38Z")

</div>

Hi all,

I was trying to run [mouse.py](http://mouse.py) in demos section of Psychopy. I am using the recent standalone version of Psychopy on MAC OS sierra.

Can anyone help me to understand why I am getting following error?

```auto
Traceback (most recent call last):
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/demos/coder/input/mouse.py", line 41, in <module>
    mouse_dX, mouse_dY = myMouse.getRel()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/event.py", line 655, in getRel
    relPos = self.getPos()
  File "/Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/event.py", line 558, in getPos
    lastPosPix = lastPosPix - self.win.size / 2
TypeError: unsupported operand type(s) for /: 'tuple' and 'int'
1.8979 WARNING Monitor specification not found. Creating a temporary one...

```

Thanks in Advance!

---

<div class="post-metadata">

**Author:** ![k\_wood](https://avatars.discourse-cdn.com/v4/letter/k/f07891/32.png) [@k\_wood](https://discourse.psychopy.org/u/k_wood)\
**Post date:** [September 26, 2017, 4:27pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/2 "2017-09-26T16:27:16Z")

</div>

I ran into this error as well. As far as I can tell, it seems to be related to a small bug in the `event.py` file that deals with calculating the updated mouse position. If you look on line 558 in this file, you’ll see this:

```auto
lastPosPix = lastPosPix - self.win.size / 2

```

The problem is that `self.win.size` here is a tuple, which does not support elementwise division or subtraction. However, `lastPosPix` is a `numpy` array, which does support these operations. I fixed this bug by editing this line like so:

```auto
lastPosPix = lastPosPix - numpy.array(self.win.size) / 2

```

That got things working for me. Hope that helps.

---

<div class="post-metadata">

**Author:** ![Iva28](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iva28](https://discourse.psychopy.org/u/Iva28)\
**Post date:** [September 26, 2017, 5:17pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/3 "2017-09-26T17:17:32Z")

</div>

Thanks ! It helped 🙂

---

<div class="post-metadata">

**Author:** ![jon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jon/32/22_2.png) [@jon](https://discourse.psychopy.org/u/jon)\
**Post date:** [September 26, 2017, 6:24pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/4 "2017-09-26T18:24:02Z")

</div>

Yes, this has been fixed in the main release now

---

<div class="post-metadata">

**Author:** ![Iva28](https://avatars.discourse-cdn.com/v4/letter/i/cab0a1/32.png) [@Iva28](https://discourse.psychopy.org/u/Iva28)\
**Post date:** [September 26, 2017, 6:41pm UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/5 "2017-09-26T18:41:34Z")

</div>

Thanks Jon. I was using the previous package of Psychopy. Now it works fine 🙂

---

<div class="post-metadata">

**Author:** ![jirilukavsky](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jirilukavsky/32/176_2.png) [@jirilukavsky](https://discourse.psychopy.org/u/jirilukavsky)\
**Post date:** [January 9, 2018, 11:24am UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/6 "2018-01-09T11:24:34Z")

</div>

The problem is still present in 1.85.6 and 1.85.3 (maybe the bug fix got lost?)

---

<div class="post-metadata">

**Author:** ![wphantomfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wphantomfr/32/12331_2.png) [@wphantomfr](https://discourse.psychopy.org/u/wphantomfr)\
**Post date:** [February 20, 2018, 7:45am UTC](https://discourse.psychopy.org/t/mouse-py-in-demos-giving-typeerror-unsupported-operand-type-s-for-tuple-and-int/3112/7 "2018-02-20T07:45:29Z")

</div>

I can confirm it’s still there in 1.85.6 ! why ? (the windows bug with the problem of encoding the name of the sound card is still there too !)
