Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import the widgets library
- from libopensesame import widgets
- # Create a form
- form = widgets.form(self.experiment, cols=[1,1], rows=[1,2,1],
- margins=(50,100,50,100), spacing=25)
- # Create four widgets
- labelTitle = widgets.label(form, text='Question')
- labelQuestion = widgets.label(form,
- text='A bat and a baseball together cost $1.10. The bat costs one dollar more than the ball. How much does the ball cost?',
- center=False)
- button5cts = widgets.button(form, text='$0.05')
- button10cts = widgets.button(form, text='$0.10')
- # Add the widgets to the form. The position in the form is indicated as a
- # (column, row) tuple.
- form.set_widget(labelTitle, (0,0), colspan=2)
- form.set_widget(labelQuestion, (0,1), colspan=2)
- form.set_widget(button5cts, (0,2))
- form.set_widget(button10cts, (1,2))
- # Normally you would call form._exec() to execute the form, or
- # form.render() to draw the form (without any interactivity).
- #button_clicked = form._exec()
- # But you can also call the render() method on the individual widgets
- # to render only a few widgets.
- button5cts.render()
- # Or even render a custom text in the widgets that support the draw_text()
- # method.
- labelTitle.draw_text('Custom text')
- # These functions affect the canvas object of the form, so to show the form
- # (or at least those parts that you have rendered manually) you need to call
- # form.canvas.show()
- form.canvas.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement