【问题标题】:How to change ipython qtconsole input如何更改 ipython qtconsole 输入
【发布时间】:2016-09-03 07:48:35
【问题描述】:

我正在使用 pyqt 制作指南,其中包含一个 ipython qtconsole 小部件。

try:
    from qtconsole.rich_jupyter_widget import RichJupyterWidget as ipythonWidget
    from qtconsole.inprocess import QtInProcessKernelManager
except:
    from IPython.qt.console.rich_ipython_widget import RichIPythonWidget as ipythonWidget
    from IPython.qt.inprocess import QtInProcessKernelManager

我想从我的代码中修改 qtconsole 输入但不工作。我已经尝试了 set_next_input 函数,但它不起作用,我找不到另一个可以用来完成我想要的函数。甚至有可能实现我想要的吗?如果是这样,我该怎么做?

这是我的代码:

try:
    from qtconsole.rich_jupyter_widget import RichJupyterWidget as ipythonWidget
    from qtconsole.inprocess import QtInProcessKernelManager
except:
    from IPython.qt.console.rich_ipython_widget import RichIPythonWidget as ipythonWidget
    from IPython.qt.inprocess import QtInProcessKernelManager

import sys
from PyQt4 import QtGui

class sympyIpython(QtGui.QWidget):

    def __init__(self):
        super().__init__()

        self.ipython = IpythonWidget()
        v = QtGui.QVBoxLayout(self)
        button = QtGui.QPushButton('append to input')
        v.addWidget(self.ipython)
        v.addWidget(button)
        button.clicked.connect(self.symClicked)

    def symClicked(self):
        self.ipython.kernel.shell.set_next_input(' appended text')

class IpythonWidget(ipythonWidget):

    def __init__(self):
        super().__init__()
        self.kernel_manager = QtInProcessKernelManager()
        self.kernel_manager.start_kernel()
        self.kernel = self.kernel_manager.kernel
        self.kernel.gui = 'qt4'
        self.kernel_client = self.kernel_manager.client()
        self.kernel_client.start_channels()

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    m = sympyIpython()
    m.show()
    sys.exit(app.exec_())

【问题讨论】:

  • 尝试设置jupyter_widget.input_buffer = 'text'
  • 非常感谢托马斯。就是这么简单!

标签: input ipython pyqt4 jupyter qtconsole


【解决方案1】:

作为答案转发:

要在 Qt 控制台的提示符处更改文本,请在小部件对象上设置 input_buffer

jupyter_widget.input_buffer = 'text'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-11
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多