【发布时间】:2017-11-23 20:50:32
【问题描述】:
我有一个 python 插件,其中main.py 文件显示QTextBrowser 并写入一些文本。这工作正常。
我编写了第二个文件anotherFile.py,它标识了相同的 QTextBrowser,但不能向其中写入任何文本。也许它需要拥有所有权,我不确定?
这里是使用的代码:
# main.py #
from Example_dockwidget import ExampleDockWidget
from anotherFile import anotherClass
class Example:
def __init__(self, iface):
self.iface = iface
def function(self):
self.dockwidget = ExampleDockWidget()
self.dockwidget.show()
textBrowser = self.dockwidget.textBrowser
#textBrowser.setText('This works!')
a = anotherClass(self)
a.anotherFunction()
# anotherFile.py #
from Example_dockwidget import ExampleDockWidget
class anotherClass:
def __init__(self, iface):
self.iface = iface
self.dockwidget = ExampleDockWidget()
def anotherFunction(self):
textBrowser = self.dockwidget.textBrowser
textBrowser.setText('This does not work!')
print 'Why?'
# Example_dockwidget.py #
FORM_CLASS, _ = uic.loadUiType(os.path.join(
os.path.dirname(__file__), 'Example_dockwidget_base.ui'))
class ExampleDockWidget(QtGui.QDockWidget, FORM_CLASS):
def __init__(self, parent=None):
super(ExampleDockWidget, self).__init__(parent)
self.setupUi(self)
【问题讨论】:
标签: python python-2.7 pyqt