(PyQtGraph)如何删除控制台小部件上的“历史记录”和“异常”按钮?

时间:2018-02-08 16:26:44

标签: python pyqtgraph

我可以使用以下命令创建一个控制台小部件:

console = pyqtgraph.console.ConsoleWidget(namespace=namespace, text='test', historyFile=None, editor=None)

但是如何删除基本上创建的“历史记录”和“例外”按钮?我提到了这个页面(http://www.pyqtgraph.org/documentation/widgets/consolewidget.html),但我找不到。

1 个答案:

答案 0 :(得分:0)

您可以按objectName:" exceptionBtn"," historyBtn"来搜索按钮。然后使用deleteLater()

删除它
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph.console

app = pg.mkQApp()
namespace = {'pg': pg, 'np': np}

## initial text to display in the console
text = """
This is an interactive python console. The numpy and pyqtgraph modules have already been imported 
as 'np' and 'pg'. 

Go, play.
"""
console = pyqtgraph.console.ConsoleWidget(namespace=namespace, text=text, historyFile=None, editor=None)
[console.findChild(QtGui.QPushButton, name).deleteLater() for name in ("exceptionBtn", "historyBtn")]
console.show()
console.setWindowTitle('pyqtgraph example: ConsoleWidget')

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

输出:

enter image description here