473,466 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

wxpython: another missing attribute

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
2 1614

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Doug Farrell | last post by:
Hi all, I just installed the wxPython-2.4.1.2 demo RPM on my RedHat Linux 9.0 machine, which has Python 2.2.2 on it, and I'm having a problem running the demo.py program. Here is a trace of the...
2
by: Axium Computer Services | last post by:
I just recently started trying to teach myself python and wxPython. The python portion of that hasn't been much of a problem as documentation seems available and of good quality. While I was...
1
by: John Kinson | last post by:
Hi, I'm trying to get the wxPython demo to run on a Debian sarge testing installation, but encounter the following error when I run the demo script: # ./demo.py Traceback (most recent call...
13
by: Peter Maas | last post by:
Recently I replaced Win2k with Linux on my desktop computer. Using mostly multi-platform software I thought this would be easy. It was not as easy as expected getting wxPython to work. There seemed...
2
by: Nicolas Pourcelot | last post by:
Hello, my script worked well until today : when I tried to launch it, I got the following : frame = MyFrame(None,-1,"Geometrie",size=wx.Size(600,400)) File...
2
by: KDawg44 | last post by:
Hi, I downloaded the wxPython demo and did an emerge wxpython (gentoo) to install. When I run the demo, I am getting this error: # python demo.py Traceback (most recent call last): File...
6
by: BartlebyScrivener | last post by:
If there is a wxPython on Debian user in the house? I am using the version of the demo that came with the apt-get download of wxPython. I thought I'd followed the instructions for installing and...
1
by: Steven W. Orr | last post by:
python-2.3.5 wx-2.6 I just bought the wxPython In Action book and I see that all the examples say to import wx All of our pre-existing code was horribly doing a from wxPython import * I...
2
by: Andrea Gavana | last post by:
Hi Ed & All, On Thu, Jun 12, 2008 at 4:11 PM, Ed Leafe wrote: Maybe. But I remember a nice quote made in the past by Roger Binns (4 years ago): """ The other thing I failed to mention is...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.