[wxPython] Beginner-> Can't access gui attributes from event proc.

Hi all,

I’m trying to duplicate a simple Vb/Access app. I’ve gotten as far

as some simple Gui construction, and db connection but

I’m stuck with the event procedures.

Basically, I’m just trying to change the text in the wxTextCtrl

as I step through the database. The error I’m receiving is:

Traceback (most recent call last):
  File "C:\Python20\wxframetest2.py", line 67, in OnNext
    self.t.Clear()
AttributeError: 'MyFrame' instance has no attribute 't'

I understand why I’m receiving the error, but I’m not sure how to

go about fixing it.

Any help would be appreciated. (Code below)

TIA,

Bill.

(edited for length – pretty much copied from the

demo:

from wxPython.wx import *
import time
import dbi
import odbc

myconn = odbc.odbc(‘PROJECTLIST’)
mycursor = myconn.cursor()
mycursor.execute(‘Select * from ProjectList’)
mydata = []

···

#---------------------------------------------------------------

class MyFrame(wxFrame):
def init(self, parent, ID, title, pos, size):
wxFrame.init(self, parent, ID, title, pos, size)
panel = wxPanel(self, -1)

    mydata = mycursor.fetchone()

    wxStaticText(panel, -1, "Data1", wxPoint(5, 25), wxSize(75, 20))
    t = wxTextCtrl(panel, 10, str(mydata[0]), wxPoint(80, 25),wxSize(150, 20))
    t.SetInsertionPoint(0)

<snip - more gui widgets here>

#Next Button
#--------------------------------------------
btn_Next = wxButton(panel, 1005, “Next”)
btn_Next.SetPosition(wxPoint(150, 125))
EVT_BUTTON(self, 1005, self.OnNext)
#--------------------------------------------

def OnNext(self, event):
    mydata = mycursor.fetchone()
    print (mydata[0])
    self.t.Clear()
    self.t.WriteText(str(mydata[0]))

Try making the t in your class Myframe self.t

···

#---------------------------------------------------------------
class MyFrame(wxFrame):
    def __init__(self, parent, ID, title, pos, size):
        wxFrame.__init__(self, parent, ID, title, pos, size)
        panel = wxPanel(self, -1)

        mydata = mycursor.fetchone()

        wxStaticText(panel, -1, "Data1", wxPoint(5, 25), wxSize(75, 20))
        t = wxTextCtrl(panel, 10, str(mydata[0]), wxPoint(80,
25),wxSize(150, 20)) t.SetInsertionPoint(0)
<snip - more gui widgets here>

#Next Button
#--------------------------------------------
        btn_Next = wxButton(panel, 1005, "Next")
        btn_Next.SetPosition(wxPoint(150, 125))
        EVT_BUTTON(self, 1005, self.OnNext)
#--------------------------------------------
<snip>

    def OnNext(self, event):
        mydata = mycursor.fetchone()
        print (mydata[0])
        self.t.Clear()
        self.t.WriteText(str(mydata[0]))

----------------------------------------
Content-Type: text/html; charset="iso-8859-1"; name="Attachment: 1"
Content-Transfer-Encoding: quoted-printable
Content-Description:
----------------------------------------

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

    Traceback (most recent call last):
      File "C:\Python20\wxframetest2.py", line 67, in OnNext
        self.t.Clear()
    AttributeError: 'MyFrame' instance has no attribute 't'

I understand why I'm receiving the error, but I'm not sure how to
go about fixing it.

If you want to access something in self, you need to put it there. In your
__init__ add this:

    self.t = t

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Thanks guys.
That's my VB hurting me there, sigh.

Just out of curiosity, who "owned" those attributes before I added self?

Bill.

···

----- Original Message -----
From: "Robin Dunn" <robind@earthling.net>
To: <wxpython-users@lists.sourceforge.net>
Sent: Thursday, March 15, 2001 10:42 PM
Subject: Re: [wxPython] Beginner-> Can't access gui attributes from event
proc.

> Traceback (most recent call last):
> File "C:\Python20\wxframetest2.py", line 67, in OnNext
> self.t.Clear()
> AttributeError: 'MyFrame' instance has no attribute 't'
>
> I understand why I'm receiving the error, but I'm not sure how to
> go about fixing it.

If you want to access something in self, you need to put it there. In

your

__init__ add this:

    self.t = t

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users

Thanks guys.
That's my VB hurting me there, sigh.

Just out of curiosity, who "owned" those attributes before I added self?

Nobody, there were not attributes but local variables of the __init__
function.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/wxpython-users