【发布时间】:2019-02-20 09:12:53
【问题描述】:
我正在为 qgis 3 编写一个 python 插件。
基本上,当用户单击它时,我会尝试获取一个功能。
mapTool.featureIdentified.connect(onFeatureIdentified)
所以在函数onfeatureIdentified
def onFeatureIdentified(feature):
print("feature selected : "+ str(feature.id()))
方法 featureIdentified 传递一个隐式参数。
void QgsMapToolIdentifyFeature::featureIdentified ( const QgsFeature & ) void QgsMapToolIdentifyFeature::featureIdentified ( QgsFeatureId )
我的问题是我想将另一个参数传递给函数(我想在识别出一个功能时关闭我的窗口) 像这样:
mapTool.featureIdentified.connect(onFeatureIdentified(window))
def onFeatureIdentified(feature,window):
print("feature selected : "+ str(feature.id()))
window.quit()
这样一来,window参数就会覆盖native方法的隐式参数。
我该怎么办?
【问题讨论】:
-
试试
mapTool.featureIdentified.connect(lambda f: onFeatureIdentified(f, window))。 -
哇,它似乎有效。我觉得很愚蠢,因为我将 lambda 用于其他功能而我忽略了它会起作用。谢谢!
标签: python function tkinter parameter-passing qgis