Advertisement
smathot

Form functions

Dec 28th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. # Import the widgets library
  2. from libopensesame import widgets
  3.  
  4. # Create a form
  5. form = widgets.form(self.experiment, cols=[1,1], rows=[1,2,1],
  6.     margins=(50,100,50,100), spacing=25)
  7.  
  8. # Create four widgets
  9. labelTitle = widgets.label(form, text='Question')
  10. labelQuestion = widgets.label(form,
  11.     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?',
  12.     center=False)
  13. button5cts = widgets.button(form, text='$0.05')
  14. button10cts = widgets.button(form, text='$0.10')
  15.  
  16. # Add the widgets to the form. The position in the form is indicated as a
  17. # (column, row) tuple.
  18. form.set_widget(labelTitle, (0,0), colspan=2)
  19. form.set_widget(labelQuestion, (0,1), colspan=2)
  20. form.set_widget(button5cts, (0,2))
  21. form.set_widget(button10cts, (1,2))
  22.  
  23. # Normally you would call form._exec() to execute the form, or
  24. # form.render() to draw the form (without any interactivity).
  25. #button_clicked = form._exec()
  26.  
  27. # But you can also call the render() method on the individual widgets
  28. # to render only a few widgets.
  29. button5cts.render()
  30.  
  31. # Or even render a custom text in the widgets that support the draw_text()
  32. # method.
  33. labelTitle.draw_text('Custom text')
  34.  
  35. # These functions affect the canvas object of the form, so to show the form
  36. # (or at least those parts that you have rendered manually) you need to call
  37. # form.canvas.show()
  38. form.canvas.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement