Book Image

Sage Beginner's Guide

By : Craig Finch
1 (1)
Book Image

Sage Beginner's Guide

1 (1)
By: Craig Finch

Overview of this book

Table of Contents (17 chapters)
Sage Beginner's Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – making interactive controls


This example consists of a gallery of all the basic controls that can be used in the Sage notebook interface. The code is followed by the result from running that code in an input cell.

@interact
def _(t=text_control('Static text goes here')):
    pass
@interact
def _(value = slider(vmin=0, vmax=10, step_size=1, default=5,
    label='Slide me:', display_value = True)):
    print value

Here is a shorthand way to create the same type of control:

@interact    # Shortcuts
def _(value1=(1..10), value2=(0,100,10), value3=(1,10)):
    print value1
    print value2
    print value3
@interact
def _(value = range_slider(0, vmax=10, step_size=1, default=(3,7),
    label='Slide me:', display_value = True)):
    print value
@interact
def _(checked = checkbox(True, "Check the box:")):
    print checked

Here is a shorthand way to create the same type of control:

@interact
def _(check_value = True):    # Shortcut
    print check_value
@interact
def _(value1 = selector...