The problem is that dict is a variable with local scope, not accessible in another function. Try using self.dict when defining and adding to the dictionary in AddZone. That way, it's will be accessible as self.dict in OnSelChanged.
Brian
anurag sharma wrote:
···
in this ,i m calling AddZone() in loop to add elements to the root of a treectrl. i want to capture click on 'i min' of Zone0 & Zone1 distinctly so i m using a global dictionary dict but the code is giving keyerror (also indicated in code below ) saying "KeyError: <wx._controls.TreeItemId; proxy of C++ wxTreeItemId instance at _283efc08_p_wxTreeItemId>". i also tried to print dict just above the error but each time dictionary had different keys(keys change when we click on different). i m totally confused about the code .please help. I M USING LINUX.
some of the functions are given below :root = self.tree.AddRoot('FILE')
for i in range(k.GetNumberOfZones()):
self.AddZone(self.tree,"Zone"+str(i),i)self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged)
def AddZone(self, tree,zone_name,k):
zone = tree.AppendItem(root, zone_name)
a=tree.AppendItem(zone, 'i min')
dict[a]=k
b=tree.AppendItem(zone, 'i max')
dict[b]=k+1
c=tree.AppendItem(zone, 'j min')
dict[c]=k+2
d=tree.AppendItem(zone, 'j max')
dict[d]=k+3
e=tree.AppendItem(zone, 'k min')
dict[e]=k+4
f=tree.AppendItem(zone, 'k max')
dict[f]=k+5
def OnSelChanged(self, event):
item = event.GetItem()
a=dict[item]# ERROR IS COMING HERE
c=a/6
d=a%6self.k.SetDisplayRegion(c,d)
--
ANURAG SHARMA