I have a python add-in for Arc using the addin-assistant. It populates values in one combo box based on the selection from the other. All of that works fine.

What I can't figure out is how to keep the selected string from the first box visible. See the image... How do I get the "Zoom to:" combo box to display the value that the user selects?

enter image description here

I must be missing something but I cannot figure out what I am missing or where to put it. Code below.

import arcpy
import pythonaddins

class ComboBoxClass7(object):
    """Implementation for arcpythonAddins_addin.combobox_1 (ComboBox)"""
    def __init__(self):
        self.items = ["quad", "county"]
        self.editable = False
        self.enabled = True
        self.dropdownWidth = 'WWWWWWWW'
        self.width = 'WWWWWWWW'
    def onSelChange(self, selection):
        combobox.enabled = True
        global fcName, fcField
        if selection == "quad":
            fcName = "quads"
            fcField = "quad"
            fcName = "counties"
            fcField = "COUNTYNM"
    def onEditChange(self, text):
    def onFocus(self, focused):
    def onEnter(self):
    def refresh(self):

class ComboBoxClass1(object):
    """Implementation for arcpythonAddins_addin.combobox (ComboBox)"""
    def __init__(self):
        self.editable = True
        self.enabled = False
        self.dropdownWidth = 'WWWWWWWWWWWW'
        self.width = 'WWWWWWWWWWW'
    def onSelChange(self, selection):
        arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION",  fcField + "='" + selection + "'")
        self.df = arcpy.mapping.ListDataFrames(self.mxd)[0]
        arcpy.SelectLayerByAttribute_management(layer, "CLEAR_SELECTION")
    def onEditChange(self, text):
    def onFocus(self, focused):
        self.mxd = arcpy.mapping.MapDocument('current')
        global layer
        layer = arcpy.mapping.ListLayers(self.mxd, fcName)[0]
        items = []
        with arcpy.da.SearchCursor(layer, [fcField]) as cursor:
            for row in cursor:
        self.items = sorted(items)
    def onEnter(self):
    def refresh(self):

I didn't test, but noticed you aren't using the 'value' property to set the combobox text box value (the displayed value) after the item selection (onSelChange). Notice the 'value' property documented here and notice the 'refresh' method use recommended in conjunction with the change in property:


Jason Scheirer shows the usage at his post here:

Refreshing Combobox of Python Add-in of ArcPy?

If I've read your objects correctly, since you'd be calling the functions within the same class (combobox_1), you can use the 'self' notation, as in self.value = selection, followed by self.refresh().

  • More explicitly, just add self.value = selection to the onSelChange method. – alphabetasoup May 11 '15 at 2:02
  • Thank you for providing such a good solution, because I have always been confused by the question. But I also would like to ask a question, that is,in the same tool bar, if there is a way to achieve the combobox be to enable when select a value by another combobox. Thanks! – T J May 12 '15 at 0:08
  • Thanks, I had tried this before, and then tried it again but no luck. What I did find out, though, is that it works when the combobox's init self.editable = True. Which I don't necessarily want it to be but it doesn't hurt if it is... – Tangnar May 12 '15 at 12:33

Because here you have the wrong line.

def onSelChange(self, selection):
    **combobox.enabled = True**

Because [combobox] is not defined.You delete this line, should be able to run. Of course, you need to change ComboBoxClass1's self.enabled to True.

As far as I know, in the toolbar's comboBox to achieve another seems more difficult to control, if you want do it,you should use python addin's extention.

  • Thanks for the reply, but I'm still looking for an answer to address my specific question. the code you mention above activates the second combo box once a selection is made in the first. All aspects work fine, I just want the text to remain in the first combo box after a selection is made. – Tangnar May 10 '15 at 22:48
  • If you want keep the value of the first combo box,you should set ComboBoxClass7's self.editable=True,Although I think this setting is very strange, but after my test, not so, the selected value really can not be displayed – T J May 11 '15 at 0:08

I actually tried, based on TJ's suggestion in a comment, just setting setting self.editable=True for the first combo box. This change allowed the selection to remain visible in the first box.

I wouldn't have thought that as my first choice, because I don't really need it to be editable (no reason for users to type anything in the box). But then again, it doesn't hurt anything if it is. So if it allows the value to be displayed in the box, great.

I did try T. Wayne Whitley's solution, but I could still not get the value to remain visible.

  • I also tried it, if you do not set the editable True, indeed not able to keep the selected results, and it seems it will not be executed onSelChange, and can not set self.value. I look at the Esri's official example, are also set to be editable True, so this may be because the Combobox of Python Addin is different to the general operation of Windows ComboBox, although I also think editable = False for what occasions some doubts, but in fact even if you change the text, there will not be any impact. – T J May 13 '15 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.