I’ve a big doubt because my script is not performing as it should be. So I’ve a simple main file with a button that opens a blank grid (codes below). The problem with this code is that it opens reportWindow the first time it executes, but if I close the report andI try to open it again I receive the error :
NameError: name ‘TestFrame’ is not defined
I’ve also removed “if name == 'main’” from the last lines of reportWindow.py because the script wasn’t working with it. I tried “if name == ‘main’” as it’s imported from main.py but it didn’t work.
Please, can someone show me how it should have been done in the first place?
Thank you
main.py
import wx
class Test(wx.Frame):
def init(self,parent,id):
wx.Frame.init(self,parent,id, “Frame aka Window”, size=(300, 200))
panel = wx.Panel(self)
button = wx.Button(panel, label = “Exit”, pos=(80, 80), size = (120,30))
self.Bind(wx.EVT_BUTTON, self.closebutton, button)
def closebutton(self,event):
from reportWindow import SimpleGrid
SimpleGrid(TestFrame, -1)
if name == ‘main’:
app = wx.App()
frame = Test(parent=None, id=1)
frame.Show()
app.MainLoop()
reportWindow.py
import wx
import wx.grid as gridlib
class SimpleGrid(gridlib.Grid): ##, mixins.GridAutoEditMixin):
def init(self, parent, log):
gridlib.Grid.init(self, parent, -1)
#[…Some code…]
class TestFrame(wx.Frame):
def init(self, parent, log):
wx.Frame.init(self, parent, 0, “Title”, size=(1400,800))
self.grid = SimpleGrid(self, log)
#[…Some code…]
#if name == ‘main’:
import sys
from wx.lib.mixins.inspection import InspectableApp
app = InspectableApp(False)
frame = TestFrame(None, sys.stdout)
frame.Show(True)
#import wx.lib.inspection
#wx.lib.inspection.InspectionTool().Show()
app.MainLoop()