By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,666 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

wxpython: another missing attribute

P: n/a
Ah, the object-oriented stuff is just so FUN! :) Here's my code,
followed by the error. I thought I was referring to the 'text' attribute
correctly, but it seems not.

import wx
class InputForm(wx.Frame):

def __init__(self, parent, id, title, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
name='frame'):
wx.Frame.__init__(self, parent, id, title, pos, size, style, name)
panel = wx.Panel(self)
text = wx.StaticText(panel, -1, 'Click results')
btnOK = wx.Button(panel, -1, 'OK')
self.Bind(wx.EVT_BUTTON, self.clickOK, btnOK)
btnCancel = wx.Button(panel, -1, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.clickCancel, btnCancel)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(btnOK, 0, wx.ALL, 10)
sizer.Add(btnCancel, 0, wx.ALL, 10)
sizer.Add(text, 0, wx.ALL, 10)
panel.SetSizer(sizer)

def clickOK(self, event):
self.text.SetLabel('You clicked OK')

def clickCancel(self, event):
self.text.SetLabel('You clicked Cancel')
class MyApp(wx.App):

def OnInit(self):
frame = InputForm(None, -1, 'Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True
app = MyApp()
app.MainLoop()

-------------------

Traceback (most recent call last):
File "C:\Python24\myscripts\wx_tests\wxtest.py", line 23, in clickOK
self.text.SetLabel('You clicked OK')
AttributeError: 'InputForm' object has no attribute 'text'
Jun 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"John Salerno" <jo******@NOSPAMgmail.com> wrote in message
news:mL******************@news.tufts.edu...
Ah, the object-oriented stuff is just so FUN! :) Here's my code,
followed by the error. I thought I was referring to the 'text' attribute
correctly, but it seems not.

import wx
class InputForm(wx.Frame):

def __init__(self, parent, id, title, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
name='frame'):
wx.Frame.__init__(self, parent, id, title, pos, size, style, name) panel = wx.Panel(self)
text = wx.StaticText(panel, -1, 'Click results')
This becomes a local var, i.e. local to __init__. To make it an instance var
write

self.text = wx.StaticText(panel, -1, 'Click results')

HTH
Morpheus

btnOK = wx.Button(panel, -1, 'OK')
self.Bind(wx.EVT_BUTTON, self.clickOK, btnOK)
btnCancel = wx.Button(panel, -1, 'Cancel')
self.Bind(wx.EVT_BUTTON, self.clickCancel, btnCancel)
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(btnOK, 0, wx.ALL, 10)
sizer.Add(btnCancel, 0, wx.ALL, 10)
sizer.Add(text, 0, wx.ALL, 10)
panel.SetSizer(sizer)

def clickOK(self, event):
self.text.SetLabel('You clicked OK')

def clickCancel(self, event):
self.text.SetLabel('You clicked Cancel')
class MyApp(wx.App):

def OnInit(self):
frame = InputForm(None, -1, 'Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True
app = MyApp()
app.MainLoop()

-------------------

Traceback (most recent call last):
File "C:\Python24\myscripts\wx_tests\wxtest.py", line 23, in clickOK
self.text.SetLabel('You clicked OK')
AttributeError: 'InputForm' object has no attribute 'text'

Jun 9 '06 #2

P: n/a
Morpheus wrote:
This becomes a local var, i.e. local to __init__. To make it an instance var
write

self.text = wx.StaticText(panel, -1, 'Click results')


Ah, more namespace trickery! Thanks! :)
Jun 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.