I am aware this might be considered a 'repeat question' however, I haven't found a similar question that answers my predicament, all the other folks with the same error had different looking code organization than mine.
I made a class for my dateFrame window and put a button in it, and OnClick() I want to call GetValue() from toCtrl and fromCtrl, but for some reason I keep getting attribute errors. Not sure where I've went wrong. OnClick() should be in the correct scope of the class to work with the objects from it.
Keep getting error:
AttributeError: 'dateFrame' object has no attribute 'toCtrl'
Here is my class dateFrame():
class dateFrame(wx.Frame):
global toText, fromText
def __init__(self):
wx.Frame.__init__(self, None, -1, 'Date Search', size=(350, 150))
panel = wx.Panel(self, -1)
fromLabel = wx.StaticText(panel, -1, "From Date:", (300, 500), (110, -1), wx.ALIGN_CENTER)
fromCtrl = wx.TextCtrl(panel, -1, "Example: 1/11/11", style=wx.TE_CENTRE, size=(150, -1))
toLabel = wx.StaticText(panel, -1, "To Date:", (100, 200), (110, -1), wx.ALIGN_CENTER)
toCtrl = wx.TextCtrl(panel, -1, "Example: 2/22/22", style=wx.TE_CENTRE, size=(150, -1))
sizer = wx.FlexGridSizer(cols=2, rows = 3, hgap=6, vgap=6)
sizer.AddMany([fromLabel, fromCtrl, toLabel, toCtrl])
#sizer1.AddStretchSpacer(1)
#sizer1.Add(panel, 0, wx.ALIGN_CENTER)
#sizer1.AddStretchSpacer(1)
#self.SetSizer(sizer1)
panel.SetSizer(sizer)
b = wx.Button(panel, 10, "Search", (120, 70))
panel.Bind(wx.EVT_BUTTON, self.OnClick, b)
b.SetDefault()
b.SetSize(b.GetBestSize())
def OnClick(self, event):
global frame, dFrame
toText = self.toCtrl.GetValue()
fromText = self.fromCtrl.GetValue()
frame.Destroy()
frame = TestFrame(None, sys.stdout)
frame.Show(True)
dFrame.Destroy()