wxpython: another missing attribute
John Salerno
johnjsal at NOSPAMgmail.com
Fri Jun 9 14:05:06 EDT 2006
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'
More information about the Python-list
mailing list