Resolver One Library Documentation

API for Button

Back to documentation index page.

Classes

Class Button

class Button(object):
    def __init__(self, Text=''):

Clickable buttons can be inserted into any cell. You can set what happens when the button is clicked e.g. add or remove data, highlight certain values, import from a database or update changes back to a database. The Button class can be used to place a button in a cell, and configure what happens when the button is clicked. You assign the cell's value where you want to place the button to be an instance of the Button class. The code below will insert a button with 'Click Me' written on it into cell A1 on the worksheet called 'Sheet1'. Once the button has been clicked, the text 'Button clicked' will appear in cell A2. If you want to reverse the action done by clicking on the button, a second button undoing the action would need to be created. However, whenever a workbook recalculates, the action of the button within the workbook is lost and the button can be clicked on again to redo the action. If, however, the button exports data to a database or does something else outside the workbook, this action is not reversed on recalculation.

You place a button in a cell by :

button = Button(Text='Click Me')
def onClick():
    workbook['Sheet1'].A2 = 'Button clicked'
button.Click += onClick

workbook['Sheet1'].A1 = button

Properties

Click

Click = property(get, set)

Click is the event hook to which button callback functions should be added, as follows:

def onClick():
    print 'Button clicked'
button.Click += onClick

Text

Text = property(get, set)

Text is a get and set property indicating the string of text that is to be displayed on the button.