使用ArcGIS Python Addin我需要在类之间更新名为phase
的全局变量。在这里,我想要做的是更新phase
变量,方法是更改ComboBoxClass1
并点击ButtonClass3
访问它。
正如您所见,我试图通过global phase = selection
def onSelChange(self, selection):
global phase = selection
但看起来这样不起作用!
import arcpy
import pythonaddins
import os
phase = ""
class ButtonClass3(object):
"""Implementation for Trace_addin.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
print global phase
class ComboBoxClass1(object):
"""Implementation for Trace_addin.combobox (ComboBox)"""
def __init__(self):
self.items = ["Phase A", "Phase B", "Phase C"]
self.editable = True
self.enabled = True
self.dropdownWidth = 'WWWWWWWWWWWWWWWWW'
self.width = 'WWWWWWWWWWWWWWWWW'
def onSelChange(self, selection):
global phase = selection
def onEditChange(self, text):
pass
def onFocus(self, focused):
pass
def onEnter(self):
pass
def refresh(self):
pass
答案 0 :(得分:2)
正如@jasonharper所说global phase
本身就是一个声明
如果您想访问phase
,则不必使用global
例如:
print phase
如果您想修改phase
,请使用:
global phase
phase = selection