ButtonStim odd spacing with text that exceeds one line

Context: Coding a study with recognition questions and two options (ButtonStim).
Problem: For options with text that exceeds one line, it’ll have odd spacing (see pictures). The text (imported from json file) is normal English with no escape characters.

Q1: How to get rid of the odd spacing in ButtonStim?
Q2: Is there any way to dynamically change the size of the ButtonStim based on the length of the text?

Windows 10
Python 3.6
PsychoPy 2021.2.2

def display_recog_ques(mywin, mymouse, data_file, ques, stim_tracker):
ques_text = ques[‘question’]
ques_img_path = ques[‘file’][1:]
ques_category = ques[‘type’]
ques_id = ques[‘id’]
opt1 = ques[‘option1’]
opt2 = ques[‘option2’]

img_stim = visual.ImageStim(mywin, image=ques_img_path, size=0.6, pos=[0, 0.5])
recog_prac_ques = visual.TextStim(mywin, pos=[0, 0.05], text=ques_text,
                                  color="black", font="calibri", height=0.07)
option1 = visual.ButtonStim(mywin, text=opt1, fillColor="lightgrey", bold=False,
                            font="Calibri", color="black", pos=[-0.3, -0.25], size=(0.55, 0.3),
                            letterHeight=0.045) #, padding=0.05)
option2 = visual.ButtonStim(mywin, text=opt2, fillColor="lightgrey", bold=False,
                            font="Calibri", color="black", pos=[0.3, -0.25], size=(0.55, 0.3),
                            letterHeight=0.045) #, padding=0.05)
likert = visual.Slider(mywin, ticks=(1, 2, 3, 4, 5, 6, 7),
                       labels=('1\nCompletely\nGuessing', '2', '3', '4', '5', '6', '7\nExtremely\nConfident\n'),
                       size=(0.6, 0.05), pos=(0, -0.5), style='rating', font='Calibri', color='black',
                       borderColor='black', fillColor='red', granularity=1)
submit_button = visual.ButtonStim(mywin, text="Submit", fillColor="lightgrey", font="Calibri", bold=False,
                                  color="black", size=(0.15, 0.1), pos=[0, -0.75], letterHeight=0.045)

choice, mymouse, likert_choice, rt = record_choice_input(mywin, mymouse, stim_tracker, likert, submit_button, option1, option2,
                                                         img_stim, recog_prac_ques)

if ques_category != "practice":
    data_file.write(f"{ques_id}, '''{ques_text}''', recognition, {ques_category}, {likert_choice}, {choice}, {rt}\n")


I’m guessing your window is using norm spatial units? Button components are based on :textbox: Textbox components, which struggle with norm units currently. It’s something we’re working on and making pretty good progress, but not quite there yet. In the meantime, the best thing to do is set the units for your Button components to be height.

You can set the width of any Textbox-derived component (including Button) to be dependent on the number of characters by setting its witdth to None, so size would be (None, 0.1) in your case.

1 Like