[Tutor] How to reference a wx.grid.Grid outside the method inwhich it was created?

Kent Johnson kent37 at tds.net
Mon Aug 11 18:45:40 CEST 2008


On Mon, Aug 11, 2008 at 12:26 PM,  <lauren at protopc.com> wrote:
> I have created a wx.grid.Grid attached to a panel which is attached to a
> frame within one method (Method #1). Inside this method I also created a
> combobox.
>
> When an item is selected in the combobox another method is called (i.e.
> When the event is called the method is run…)
> Inside this method I want to fill the grid created in Method #1 with data
> generated/calculated from within Method #2 based on which item was
> selected from the combobox.
>
> How do I reference the grid from method #1 when I am in method #2?
>
> Currently I am receving this error message:
> "NameError: global name 'myGrid' is not defined."
>
> It's an error against this statement in method #2:
> myGrid.SetCellValue(i, 0, myValue)

If method1 and method2 are both methods of the same class, just save
myGrid as an attribute of the class rather than having it as a local
variable in method1. I.e.

def method1(self):
  self.myGrid = ...

def method2(self):
  self.myGrid.SetCellValue(...)

Kent


More information about the Tutor mailing list