Button functions
class Button
The Button
widget is a clickable text string, by default surrounded by
a button-like frame.
Example (OpenSesame script):
widget 0 0 1 1 button text='Click me!' center='yes' frame='yes' var='response'
Defining a button widget with Python inline code:
Example (Python):
form = Form()
button = Button(text='Click me!', frame=True, center=True, var='response')
form.set_widget(button, (0,0))
form._exec()
- class Button
- function Button.__init__(form, text=u'button', frame=True, center=True, var=None)
- function Button._init_canvas_elements()
- function Button._update()
- function Button._update_frame(rect=None, style=u'normal')
- function Button._update_text(text)
- function Button.coroutine()
- function Button.on_key_press(key)
- function Button.on_mouse_click(pos)
- function Button.set_rect(rect)
- function Button.set_var(val, var=None)
function Button.__init__(form, text=u'button', frame=True, center=True, var=None)
Constructor to create a new Button
object. You do not generally
call this constructor directly, but use the Button()
factory
function, which is described here: /python/common/.
Arguments:
form
-- The parent form.- Type: form
Keywords:
text
-- Button text.- Type: str, unicode
- Default: 'button'
frame
-- Indicates whether a frame should be drawn around the widget.- Type: bool
- Default: True
center
-- Indicates whether the text should be centered.- Type: bool
- Default: True
var
-- The name of the experimental variable that should be used to log the widget status.- Type: str, unicode, NoneType
- Default: None
function Button._init_canvas_elements()
Initializes all canvas elements.
function Button._update()
Draws the widget.
function Button._update_frame(rect=None, style=u'normal')
Draws a simple frame around the widget.
Keywords:
rect
-- A (left, top, width, height) tuple for the frame geometry orNone
to use the widget geometry.- Type: tuple, NoneType
- Default: None
style
-- A visual style. Should be 'normal', 'active', or 'light'.- Type: str, unicode
- Default: 'normal'
function Button._update_text(text)
Draws text inside the widget.
Arguments:
text
-- The text to draw.- Type: str, unicode
function Button.coroutine()
Implements the interaction. This can be overridden to implement more complicated keyboard/ mouse interactions.
function Button.on_key_press(key)
Is called whenever the widget is focused and the users enters a key.
Arguments:
key
-- A key- Type: str
function Button.on_mouse_click(pos)
Is called when the user clicks on the button. Returns the button text.
Arguments:
pos
-- An (x, y) coordinates tuple.- Type: tuple
Returns:
The button text.
- Type: unicode
function Button.set_rect(rect)
Sets the widget geometry.
Arguments:
rect
-- A (left, top, width, height) tuple.- Type: tuple
function Button.set_var(val, var=None)
Sets an experimental variable.
Arguments:
val
-- A value.
Keywords:
var
-- A variable name, or None to use widget default.- Type: str, unicode, NoneType
- Default: None