SigmundAI Copilot allows you to build and debug experiments with help from artificial intelligence. Install the Sigmund extension (public beta) and try it out now!
表单小部件和关键词
截图
Figure 1. 可用的form小部件列表。
小部件和关键词
所有关键词都是可选的,除非另有说明。
表格
cols
和 rows
关键词可以是单个 int
值,在这种情况下,它们指定相等大小的列和行的数量,或者可以是 int
列表,在这种情况下,它们指定每列和行的相对大小。有关表单几何的更多信息,请参见:
validator
关键词可用于验证表单输入。要了解更多信息,请参阅:
(在 OpenSesame 脚本中,您不需要显式创建表单。)
Python 脚本:
form = Form(
cols=2, rows=2, spacing=10, margins=(100, 100, 100, 100), theme='gray',
timeout=None, clicks=False, validator=None
)
button = Button(text='Ok!')
form.set_widget(button, (0, 0))
form._exec()
button / 按钮
OpenSesame 脚本:
widget 0 0 1 1 button text="Click me!" center=yes frame=yes var=response
Python 脚本:
form = Form()
button = Button(text='Click me!', frame=True, center=True, var='response')
form.set_widget(button, (0, 0))
form._exec()
checkbox / 复选框
如果指定了一组,选中该组中的一个复选框将取消选中该组中的所有其他复选框。组中的复选框不能被取消选中,除非单击该组中的另一个复选框。
group
关键词还会影响变量的存储方式,如下所述:
OpenSesame 脚本:
widget 0 0 1 1 checkbox group=group text="Option 1"
widget 0 1 1 1 checkbox group=group text="Option 2"
Python 脚本:
form = Form()
checkbox1 = Checkbox(text='Option 1', group='group')
checkbox2 = Checkbox(text='Option 2', group='group')
form.set_widget(checkbox1, (0, 0))
form.set_widget(checkbox2, (0, 1))
form._exec()
image / ImageWidget
Python 对象称为 ImageWidget
,以区别于 Image
画布元素。
OpenSesame 脚本:
# 仅路径是必需的关键字
widget 0 0 1 1 image path="my_image.png" adjust=yes frame=no
Python 脚本:
# 仅路径是必需的关键字
form = Form()
image = ImageWidget(path=pool['my_image.png'], adjust=True, frame=False)
form.set_widget(image, (0, 0))
form._exec()
image_button / 图片按钮
image_id
关键字用于在单击图片按钮时识别它。如果没有提供 image_id
,则使用图像路径作为 id。
OpenSesame 脚本:
# 仅路径是必需的关键字
widget 0 0 1 1 image_button path="my_image.png" adjust=yes frame=no image_id=my_image var=response
Python 脚本:
# 仅路径是必需的关键字
form = Form()
image_button = ImageButton(
path=pool['my_image.png'], adjust=True, frame=False,
image_id='my_image', var='response'
)
form.set_widget(image_button, (0, 0))
form._exec()
label / 标签
OpenSesame 脚本:
widget 0 0 1 1 label text="My text" frame=no center=yes
Python 脚本:
form = Form()
label = Label(text='My text', frame=False, center=True)
form.set_widget(label, (0,0))
form._exec()
rating_scale / 评分量表
nodes
关键词可以是 int
或分号分隔的标签列表。如果 nodes
是 int
,则指定数量的(无标签)节点。
default
关键词表示默认情况下选择哪个节点号,其中第一个节点为 0。
OpenSesame 脚本:
widget 0 1 1 1 rating_scale var=response nodes="Agree;Don't know;Disagree" click_accepts=no orientation=horizontal var=response default=0
Python 脚本:
form = Form()
rating_scale = RatingScale(
nodes=['同意', u"不知道", '不同意'], click_accepts=False,
orientation='horizontal', var='response', default=0
)
form.set_widget(rating_scale, (0, 0))
form._exec()
text_input / TextInput
stub
关键字表示在没有输入文本时显示的占位符文本。key_filter
关键字(仅在 Python 中可用)指定用于过滤按键的函数。这在以下内容中有更详细的描述:
OpenSesame 脚本:
widget 0 0 1 1 text_input text="初始文本" frame=yes center=no stub="在此输入 …" return_accepts=yes var=response
Python 脚本:
form = Form()
text_input = TextInput(
text='初始文本', frame=True, center=False, stub='在此输入 …',
return_accepts=True, var='response', key_filter=my_filter_function
)
form.set_widget(text_input, (0, 0))
form._exec()