Menu.Append returning None

Hello all,

For some reason tmp_menu.Append is returning None intermittently for the following line of code.

                cancel = tmp_menu.Append(-1, canceltxt, "", wx.ITEM_NORMAL)

When I try to set an attribute of cancel I get:

  AttributeError: 'NoneType' object has no attribute 'GetId'

Any ideas as to what could cause this? How to fix?

Thank you,

Rob.

Robert Liebeskind wrote:

Hello all,

For some reason tmp_menu.Append is returning None intermittently for the following line of code.

               cancel = tmp_menu.Append(-1, canceltxt, "", wx.ITEM_NORMAL)

When I try to set an attribute of cancel I get:

    AttributeError: 'NoneType' object has no attribute 'GetId'

Any ideas as to what could cause this? How to fix?

Thank you,

Rob.
_______

My guess is that you are shadowing your own variable. This is easy enough to find out. Put a print statement in your code wherever you use the object like this:

print type(cancel)

It should say that it's some kind of wx.Menu object. If not, then you've gotten the variable remapped. Here's a silly example of remapping a variable:

<code>

>>> x = list()
>>> x.append(1)
>>> x
[1]
>>> x = dict()
>>> x.append(1)

Traceback (most recent call last):
  File "<pyshell#15>", line 1, in <module>
    x.append(1)
AttributeError: 'dict' object has no attribute 'append'

</code>

HTH

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org