Skip to main content
`Ctrl`+`K`

# ConsoleWidget

class pyqtgraph.console.ConsoleWidget(

  parent=None,
  namespace=None,
  historyFile=None,
  text=None,
  editor=None,
  allowNonGuiExecution=False,

)

  Widget displaying console output and accepting command input. Implements:

  > - eval python expressions / exec python statements

  > - storable history of commands

  > - exception handling allowing commands to be interpreted in the context of any level in the exception stack frame

  Why not just use python in an interactive shell (or ipython) ? There are a few reasons:

  > - pyside does not yet allow Qt event processing and interactive shell at the same time

  > - on some systems, typing in the console _blocks_ the qt event loop until the user presses enter. This can be baffling and frustrating to users since it would appear the program has frozen.

  > - some terminals (eg windows cmd.exe) have notoriously unfriendly interfaces

  > - ability to add extra features like exception stack introspection

  > - ability to have multiple interactive prompts, including for spawned sub-processes

  > - ability to execute in either the GUI thread or a separate thread

  __init__(
    parent=None,
    namespace=None,
    historyFile=None,
    text=None,
    editor=None,
    allowNonGuiExecution=False,
  )

    Arguments: |
    namespace | dictionary containing the initial variables present in the default namespace
    historyFile | optional file for storing command history
    text | initial text to display in the console window

    editor

    optional string for invoking code editor (called when stack trace entries are double-clicked). May contain {fileName} and {lineNum} format keys. Example:

        editorCommand --loadfile {fileName} --gotoline {lineNum}

  loadHistory()

    Return the list of previously-invoked command strings (or None).

  saveHistory(
    history,
  )

    Store the list of previously-invoked command strings.