473,785 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
+ 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.Fr ame):

def __init__(self, parent, id, title, pos=wx.DefaultP osition,
size=wx.Default Size, style=wx.DEFAUL T_FRAME_STYLE,
name='frame'):
wx.Frame.__init __(self, parent, id, title, pos, size, style, name)
panel = wx.Panel(self)
text = wx.StaticText(p anel, -1, 'Click results')
btnOK = wx.Button(panel , -1, 'OK')
self.Bind(wx.EV T_BUTTON, self.clickOK, btnOK)
btnCancel = wx.Button(panel , -1, 'Cancel')
self.Bind(wx.EV T_BUTTON, self.clickCance l, btnCancel)
sizer = wx.BoxSizer(wx. HORIZONTAL)
sizer.Add(btnOK , 0, wx.ALL, 10)
sizer.Add(btnCa ncel, 0, wx.ALL, 10)
sizer.Add(text, 0, wx.ALL, 10)
panel.SetSizer( sizer)

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

def clickCancel(sel f, event):
self.text.SetLa bel('You clicked Cancel')
class MyApp(wx.App):

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

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

Traceback (most recent call last):
File "C:\Python24\my scripts\wx_test s\wxtest.py", line 23, in clickOK
self.text.SetLa bel('You clicked OK')
AttributeError: 'InputForm' object has no attribute 'text'
Jun 9 '06 #1
2 1630

"John Salerno" <jo******@NOSPA Mgmail.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.Fr ame):

def __init__(self, parent, id, title, pos=wx.DefaultP osition,
size=wx.Default Size, style=wx.DEFAUL T_FRAME_STYLE,
name='frame'):
wx.Frame.__init __(self, parent, id, title, pos, size, style, name) panel = wx.Panel(self)
text = wx.StaticText(p anel, -1, 'Click results')
This becomes a local var, i.e. local to __init__. To make it an instance var
write

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

HTH
Morpheus

btnOK = wx.Button(panel , -1, 'OK')
self.Bind(wx.EV T_BUTTON, self.clickOK, btnOK)
btnCancel = wx.Button(panel , -1, 'Cancel')
self.Bind(wx.EV T_BUTTON, self.clickCance l, btnCancel)
sizer = wx.BoxSizer(wx. HORIZONTAL)
sizer.Add(btnOK , 0, wx.ALL, 10)
sizer.Add(btnCa ncel, 0, wx.ALL, 10)
sizer.Add(text, 0, wx.ALL, 10)
panel.SetSizer( sizer)

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

def clickCancel(sel f, event):
self.text.SetLa bel('You clicked Cancel')
class MyApp(wx.App):

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

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

Traceback (most recent call last):
File "C:\Python24\my scripts\wx_test s\wxtest.py", line 23, in clickOK
self.text.SetLa bel('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(p anel, -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
1442
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 results: python demo.py The font "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1, -*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1, -*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15,
2
1418
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 working with wxPython I was beginning to think I was a little dense and missing something very important. Then I started reading the thread about python documentation and in particular the part about wxPython documentation. That made me feel so...
1
2109
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 last): File "./demo.py", line 4, in ? Main.main() File "/root/Python/wxPython-2.5.1.5/demo/Main.py", line 946, in main
13
4590
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 to be no SuSE RPM so I installed from source. Here are my steps (gtk 2.4 was already installed): - Built wxWidgets (.configure --enable-unicode) - Built wxPython (python setup.py install) error: "you should use wx-config program for...
2
2278
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 "/home/nico/Desktop/wxGeometrie/version 0.73/geometrie.py", line 74, in __init__ self.commande.Bind(wx.EVT_CHAR, self.EvtChar) AttributeError: wxTextCtrl instance has no attribute 'Bind'
2
2168
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 "/usr/lib/python2.4/site-packages/wx-2.6-gtk2-ansi/wx/ _misc.py", line 1286, in Notify
6
1843
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 unpacking the wxPython demo program. It appears to run after a fashion, but I also get this at the commandline. Any help much appreciated. (python:5865): Gtk-CRITICAL **: gtk_window_realize_icon: assertion
1
2385
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 changed all the code so that it was doing an import wx and found that
2
1023
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 that the wxPython API isn't very Pythonic. (This doesn't matter to people like me who are used to GUI
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.