# Scrollable TextBox2?

**URL:** <https://discourse.psychopy.org/t/scrollable-textbox2/30133>\
**Category:** Coding\
**Created:** [July 23, 2022, 9:59am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133 "2022-07-23T09:59:47Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dana\_Oshiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dana_oshiro/32/34573_2.png) [@Dana\_Oshiro](https://discourse.psychopy.org/u/Dana_Oshiro)\
**Post date:** [July 23, 2022, 9:59am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/1 "2022-07-23T09:59:47Z")

</div>

Hi! I am using TextBox2 to create a typed response. However, I want the participants to be able to write as much as they desire. Is there a good way to make only the textbox scrollable.

Note: I have seen a scrolling text using a rectangle to crop the bottom of the text that is being show. However, I have two stimuli on the bottom that can’t be covered. Any ideas?

Very much appreciated!!

---

<div class="post-metadata">

**Author:** ![Becca](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/becca/32/34260_2.png) [@Becca](https://discourse.psychopy.org/u/Becca)\
**Post date:** [July 23, 2022, 3:49pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/2 "2022-07-23T15:49:14Z")

</div>

Hi There,

I think if you use textbox in builder in the current release it does this (scrollable textbox) so if you are trying to code something maybe go to builder then compile and editable textbox from there?

Becca

---

<div class="post-metadata">

**Author:** ![Dana\_Oshiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dana_oshiro/32/34573_2.png) [@Dana\_Oshiro](https://discourse.psychopy.org/u/Dana_Oshiro)\
**Post date:** [July 23, 2022, 5:41pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/3 "2022-07-23T17:41:47Z")

</div>

Hi Becca  
Thank you so much for your reply! I was using the 2021 version but I downloaded the most recent version. I am not sure what feature I turn on to do this?! I don’t believe I see any explicit “scroll” feature on builder.

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [July 26, 2022, 12:46pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/4 "2022-07-26T12:46:03Z")

</div>

I think Becca may be referring to running online, I’m guessing you are running locally? I don’t think the :textbox: Textbox component can natively scroll when running locally, but it is achievable using code. I’ll have a crack at it myself now and get back to you with a solution.

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [July 26, 2022, 1:54pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/5 "2022-07-26T13:54:21Z")

</div>

What I did to get this to work is as follows:

- Create an :aperture: Aperture component with the same size, position, units, shape, etc. as the :textbox: Textbox component

- Create a :slider: Slider component with the following parameters in the Basic and Layout tabs:  

- Create a :code: Code component with this in the Each Frame tab:

```auto
if textbox.status == STARTED:
    # Update textbox text according to scrollbar
    textbox.contentBox.pos = textbox.pos + (0, textbox.contentBox.size[1] * -scrollbar.markerPos)
    textbox._needVertexUpdate = True
    # Disable automatic textbox drawing (but don't change its status)
    ogStatus = textbox.status
    textbox.setAutoDraw(False)
    textbox.status = ogStatus
    # Draw textbox manually with aperture enabled
    aperture.enable()
    textbox.draw()
    aperture.disable()

```

You can replace any reference to `textbox` in the code shown above with whatever your textbox is called, and this should work - importantly, without obscuring any other stimuli behind the :aperture: Aperture component.

---

<div class="post-metadata">

**Author:** ![Dana\_Oshiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dana_oshiro/32/34573_2.png) [@Dana\_Oshiro](https://discourse.psychopy.org/u/Dana_Oshiro)\
**Post date:** [July 27, 2022, 4:19am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/6 "2022-07-27T04:19:07Z")

</div>

Thank you so much! I am going to test it out as I add in the stimuli! We are changing some things around so its been chaotic but thank you very much!

---

<div class="post-metadata">

**Author:** ![Michaeljc53](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Michaeljc53](https://discourse.psychopy.org/u/Michaeljc53)\
**Post date:** [December 9, 2022, 2:01pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/7 "2022-12-09T14:01:22Z")

</div>

Hi! I don’t know if this thread will still be active but thought it was worth a try - I’m basically trying to do the same thing as OP, and have tried to use this method, but I’m getting the following error from the code component section (Sb\_narration\_box is the name of my textbox):

```
Sb_narration_box.contentBox.pos = Sb_narration_box.pos + (0, Sb_narration_box.contentBox.size[1] * -Sb_scrollbar.markerPos)

```

TypeError: bad operand type for unary -: ‘NoneType’

Any idea what might be the cause of this? I’m very new to Python and to Psychopy so it may be something extremely simple - sorry if that’s the case!

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [December 10, 2022, 9:32pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/8 "2022-12-10T21:32:10Z")

</div>

Have you given the slider a starting value? If not then markerPos will be None, which would explain the error

---

<div class="post-metadata">

**Author:** ![Michaeljc53](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Michaeljc53](https://discourse.psychopy.org/u/Michaeljc53)\
**Post date:** [December 13, 2022, 11:43am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/9 "2022-12-13T11:43:33Z")

</div>

I see, thank you! I put 0 in the starting value box as that’s what was in the slider properties ‘basic’ tab on your image above. What should it be?

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [December 14, 2022, 12:14am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/10 "2022-12-14T00:14:53Z")

</div>

Strange, 0 should be fine… What happens if you add a line in the Begin Routine tab to set the marker pos to 0? If that fixes it then it suggests the start value from Builder isn’t being applied for some reason

---

<div class="post-metadata">

**Author:** ![Michaeljc53](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Michaeljc53](https://discourse.psychopy.org/u/Michaeljc53)\
**Post date:** [January 16, 2023, 1:00pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/11 "2023-01-16T13:00:37Z")

</div>

What exactly would that code be? Sorry I’m new to coding!

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [January 16, 2023, 1:55pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/12 "2023-01-16T13:55:57Z")

</div>

It would be `scrollbar.markerPos = 0` 🙂

By the way, since first suggesting this fix I’ve implemented it in the actual code for Textbox, so when v2023.1.0 is out (hopefully soon!), textboxes should be able to scroll without any code - you’ll be able to control it via the parameter “overflow” in the Layout tab of a :textbox: Textbox component.

---

<div class="post-metadata">

**Author:** ![Michaeljc53](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Michaeljc53](https://discourse.psychopy.org/u/Michaeljc53)\
**Post date:** [January 16, 2023, 2:29pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/13 "2023-01-16T14:29:49Z")

</div>

Thank you for getting back so quickly! Oh that’s great news that it’s being integrated into the builder component - hopefully I won’t have to fight with it anymore after the update then!

Until then, the code seems to have worked, but it’s all quite wonky as you can see in the picture below:

![Scrollable textbox issue](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/7/e74f39bcbb5d13d1be97a6f9ae60f3f501061faf.jpeg)

As you can see, the starting text in the textbox is at the bottom intersecting with the lower border of the textbox, the top part of the textbox appears to be blocked off, and the scrollbar is scrolled to the bottom. When you scroll up, the text scrolls downwards out of sight. And when you input enough text to get to a new line, the text just continues out of the textbox rather than being able to scroll down to it.

In a sense, it’s kind of like everything’s backwards I guess… almost certainly something I’ve overlooked. Any suggestions? Thank you so much for your help.

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [January 16, 2023, 2:48pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/14 "2023-01-16T14:48:26Z")

</div>

Actually I think it’s a flaw in the screenshot I sent! I forgot to set the ticks to be `(0, 1)` on the :slider: Slider component - it’s going out of sight because rather than going from the top (0) to the bottom (1) the adjustment is going from the bottom (1) to 5 times its size below the bottom (5)…

---

<div class="post-metadata">

**Author:** ![Michaeljc53](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@Michaeljc53](https://discourse.psychopy.org/u/Michaeljc53)\
**Post date:** [January 16, 2023, 3:20pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/15 "2023-01-16T15:20:33Z")

</div>

Ok that seems to have done something positive! I think my aperture is the wrong shape and/or size though. When I tell it to take a rectangle shape in the component basic settings (like the textbox), it errors out with this message:

win=self.win, vertices=vertices, fillColor=1, lineColor=None, colorSpace=‘rgb’,  
UnboundLocalError: local variable ‘vertices’ referenced before assignment

So I made it a ‘custom polygon’ and tried to input the vertices of the textbox manually. Think it’s safe to say I’ve got it wrong! Here are screenshots of my textbox layout settings and aperture settings:

 ![aperture settings](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/5/451cadb699a5f1c0839361491913b0c57ecb90fb.jpeg)

 ![textbox settings](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/7/c78ac569d88d36e1effdbae6ba2373ee7abb8b8c.jpeg)

I guess I’ve got the vertices wrong?

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [January 17, 2023, 11:03am UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/16 "2023-01-17T11:03:45Z")

</div>

Vertices are relative to the size and position of the shape, so for a simple rectangle they don’t need to be matched to the textbox - you should be fine just setting it to be a rectangle. Is the anchor on the textbox set to “bottom center”? As your aperture’s anchor is “center” that would explain why it’s offset like in the picture

---

<div class="post-metadata">

**Author:** ![electricwitch](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@electricwitch](https://discourse.psychopy.org/u/electricwitch)\
**Post date:** [January 17, 2023, 8:48pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/17 "2023-01-17T20:48:33Z")

</div>

Hello! I am attempting to create a scrollable text box in my experiment too and seem to have encountered a similar error message to Michaeljc53 when implementing the aperture. I decided to create a new experiment with nothing but the textbox and aperture in order to simplify things while getting to grips with the problem and received the following error message:

```auto
11.9224 DEPRECATION Unrecognized shape for aperture. Expected 'circle', 'square', 'triangle', vertices, filename, or None; got 'rectangle'

```

The programme does not appear to recognise ‘rectangle’ as a valid input, despite this being an option in the drop down menu for ‘shape’ in builder mode. When I go into the code editor and manually replace ‘rectangle’ with ‘square’ it runs fine. The problem is that there is no option for ‘square’ in the drop down menu. This means if I want to adjust the aperture parameters in builder mode it automatically reverts ‘shape’ back to ‘rectangle’ and the same problem occurs again.

How to resolve this when it seems to be an issue within PsychoPy rather than user error? Is there any way to ensure ‘shape’ is permanently set to ‘square’ and does not revert back to ‘rectangle’ when altering parameters?

Many thanks for your help!

---

<div class="post-metadata">

**Author:** ![TParsons](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/tparsons/32/8301_2.png) [@TParsons](https://discourse.psychopy.org/u/TParsons)\
**Post date:** [January 17, 2023, 8:57pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/18 "2023-01-17T20:57:47Z")

</div>

I’ll make sure the name is correct for the next version! From memory I think I remember catching that one but I’ll go back and make sure.

In the meantime you could edit the .psyexp file in a text editor - a .psyexp file is actually just an .xml file which knows to open in PsychoPy. If you right click and choose “open with…” you can open it in Notepad or whatever text editor you prefer. Look for the `<ApertureComponent ...>` tag, underneath it should be a load of `<Param ...>` tags, one of which should have `"square"` for it’s value. If you replace the word square there with rectangle and then save, when you open again in Builder you should see the value “rectangle” there in the component dialog.

---

<div class="post-metadata">

**Author:** ![electricwitch](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@electricwitch](https://discourse.psychopy.org/u/electricwitch)\
**Post date:** [January 17, 2023, 9:04pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/19 "2023-01-17T21:04:35Z")

</div>

Thank you! I’ll have a go at this and let you know if I have any issues

---

<div class="post-metadata">

**Author:** ![electricwitch](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@electricwitch](https://discourse.psychopy.org/u/electricwitch)\
**Post date:** [January 18, 2023, 1:57pm UTC](https://discourse.psychopy.org/t/scrollable-textbox2/30133/20 "2023-01-18T13:57:06Z")

</div>

I have implemented your method for creating the scrollable textbox and have encountered a couple of problems:

1. The text does not appear until the scrollbar has been scrolled about halfway. Is there a way to amend this so that the top of the text aligns with the top of the scrollbar?
2. The length and scrollbar position does not align with the textbox. What parameters do I need to adjust to amend this?

Thanks again for your help!

 ![textscrolltest1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/1/c/1ce3db2bb09e96fe6866320302a2b3f2eac0536b.png)  
 ![textscrolltest2](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/1/e1a74e74f9ef0aca863455ac348ac19c29d2f4fa.png)  
 ![textscrolltest3](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/c/5c19ca0926b835e9b7a6a9e065a48a7b5fdd612d.png)  
 ![textscrolltest4](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/7/a7d084429f4f4543716350bd39b5c5401759a903.png)

[Next page](https://discourse.psychopy.org/t/scrollable-textbox2/30133.md?page=2)
