module ipythonhelper.html_forms

Short summary

module pyquickhelper.ipythonhelper.html_forms

Some functions to interact better with Notebook

source on GitHub

Functions

function

truncated documentation

open_html_form

The function displays a form onto a notebook, it requires a notebook to be open.

Documentation

Some functions to interact better with Notebook

source on GitHub

pyquickhelper.ipythonhelper.html_forms.open_html_form(params, title='', key_save='', style='background-color:gainsboro; padding:2px; border:0px;', raw=False, hook=None)[source]

The function displays a form onto a notebook, it requires a notebook to be open.

Parameters:
  • params – dictionary of parameters (see comment below)

  • title – titre of the added box

  • style – style of the form

  • key_save – name of the variable to add to the notebook (as a dictionary)

  • raw – returns the raw HTML and not HTML( text )

  • hook – an instruction as a string which will be executed if the button is clicked (None for none)

Returns:

HTML

The code comes from IPython Notebook: Javascript/Python Bi-directional Communication. When the notebook is converted into a HTML document, the values in the form do not appear. This behaviour is expected in case one of the field contains a password. On a notebook, it gives the following result:

Open a add a form in a notebook to ask parameters to a user

pyquickhelper/ipythonhelper/images/form.png

Cell 1:

from pyquickhelper.ipythonhelper import open_html_form
params = { "module":, "version":"v..." }
open_html_form (params, title="try the password *", key_save="form1")

Cell 2:

print(form1)

We can execute a simple action after the button Ok is pressed. This second trick comes from this notebook. The code displays whatever comes from function custom_action in this case. You should return "" to display nothing.

def custom_action(x):
    x["combined"] = x["first_name"] + " " + x["last_name"]
    return x

params = { "first_name":"", "last_name":"" }
open_html_form(params, title="enter your name", key_save="my_address",
               hook="custom_action(my_address)")

The function generates javascript based on the keys the dictionary params contains. The keys must follows the same as a javascript identifier (no space).

source on GitHub