Skip to main content
`Ctrl`+`K`

# `console`: IPython console widgets

This module provides an IPython console widget.

You can push variables - any python object - to the console’s interactive namespace. This provides users with an advanced way of interacting with your program. For instance, if your program has a `PlotWidget` or a `PlotWindow`, you can push a reference to these widgets to allow your users to add curves, save data to files… by using the widgets’ methods from the console.

Note

This module has a dependency on qtconsole. An `ImportError` will be raised if it is imported while the dependencies are not satisfied.

Basic usage example:

    from silx.gui import qt
    from silx.gui.console import IPythonWidget

    app = qt.QApplication([])

    hello_button = qt.QPushButton("Hello World!", None)
    hello_button.show()

    console = IPythonWidget()
    console.show()
    console.pushVariables({"the_button": hello_button})

    app.exec()

This program will display a console widget and a push button in two separate windows. You will be able to interact with the button from the console, for example change its text:

    >>> the_button.setText("Spam spam")

An IPython interactive console is a powerful tool that enables you to work with data and plot it. See this tutorial for more information on some of the rich features of IPython.

class IPythonWidget(**kwargs: Any)

  Live IPython console widget.

  Parameters:

    custom_banner – Custom welcome message to be printed at the top of the console.

  pushVariables(variable_dict)

    Given a dictionary containing name / value pairs, push those variables to the IPython console widget.

    Parameters:

      variable_dict – Dictionary of variables to be pushed to the console’s interactive namespace (``{variable_name: object, …}``)

class IPythonDockWidget(parent=None, available_vars=None, custom_banner=None, title='Console')

  Dock Widget including a `IPythonWidget` inside a vertical layout.

  Parameters:

    - available_vars – Dictionary of variables to be pushed to the console’s interactive namespace: `{"variable_name": object, …}`

    - custom_banner – Custom welcome message to be printed at the top of the console

    - title – Dock widget title

    - parent – Parent `qt.QMainWindow` containing this `qt.QDockWidget`