1

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

1 Answer 1

2

Maybe it's because you're saying:

tc_MainDatabase = wx.TextCtrl(panel)

instead of:

self.tc_MainDatabase = wx.TextCtrl(panel)
Sign up to request clarification or add additional context in comments.

1 Comment

I feel like a moron. :) Thanks. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.