wxPython: Object has no attribute error
teaching myself Python and wxPython. Not sure what I am doing wrong here, could use some insight from folks much smarter than myself...
import wx
from wxPython.wx import *
class myGUI(wx.Frame):
def __init__(self, parent, title):
super(myGUI, self).__init__(parent, title=title,
size=(450, 350))
panel = wx.Panel(self)
sizer = wx.GridBagSizer(5, 5)
# Main Database Text, Entry and Browse Button ------------------------------
label_MainDatabase = wx.StaticText(panel, label="Main Database:")
sizer.Add(label_MainDatabase, pos=(0, 0), flag=wx.LEFT|
wx.ALIGN_CENTER_VERTICAL, border=20)
tc_MainDatabase = wx.TextCtrl(panel)
sizer.Add(tc_MainDatabase, pos=(0, 1), span=(1, 3), flag=wx.TOP|
wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)
tc_MainDatabase.Value = "DBG: I am properly initialized."
bt_MainDatabase = wx.Button(panel, label="Browse...")
sizer.Add(bt_MainDatabase, pos=(0, 4), flag=wx.LEFT|wx.RIGHT|
wx.ALIGN_CENTER_VERTICAL, border=0)
bt开发者_如何转开发_MainDatabase.Bind(wx.EVT_BUTTON, self.bt_MainDatabaseClick,
bt_MainDatabase)
# --------------------------------------------------------------------------
sizer.AddGrowableCol(2)
panel.SetSizer(sizer)
self.Centre()
self.Show()
def bt_MainDatabaseClick(self, event):
# Create a list of filters
self.tc_MainDatabase.SetValue = "A"
if __name__ == '__main__':
app = wx.App()
myGUI(None, title="myGUI")
app.MainLoop()
I get the following error when I click the "Browse" button: AttributeError: 'myGUI' object has no attribute 'tc_MainDatabase'
What am I doing wrong? I am trying to capture information from the Browse button and then update a text control field (tc_MainDatabase). I've tried rearranging the order of the def statements, etc.
And yes, I always jump in with both feet. It's the only way I know how to learn... :)
Thanks.
-Chow
Maybe it's because you're saying:
tc_MainDatabase = wx.TextCtrl(panel)
instead of:
self.tc_MainDatabase = wx.TextCtrl(panel)
精彩评论