Robin told you the right answer, but since you seem to be just starting out,
and since you seem to be a bit confused by the event procedures, I wanted to
suggest some other things as well.
Tim Roberts wrote:
You should be able to replace that entire procedure with:
def OnFindButton1(self,event):
self.logger.AppendText('Found %s\n' % self.editname.GetValue())#===========================================================================
Your code worked OK, but I am still puzzled by what is returned when the
button is pushed.
NOTHING is returned. Event handlers don't return anything. They just run.
When the button is pushed, OnFindButton1 will automatically be called. It
will take some action and then exit back to the windowing system until the
next event happens.
I modified the above code to:
#=================================================
def OnFindButton1(self,event):
self.logger.AppendText('Found %s\n' %self.editname.GetValue())
a = self.editname.GetValue()
print 'This is the value of a: ',a
print 'a is of type ',type(a)
return self.editname.GetValue()stuff = OnFindButton1
print 'Returned stuff from OnFindButton1 ',stuff
print 'stuff is of type ',type(stuff)
print ''#=================================================
#..............which returns the following information:pythonw -u Address2.py
Returned stuff from OnFindButton1 <function OnFindButton1 at 01545D0C>
stuff is of type <type 'function'>
As Robin said, OnFindButton1 is a function. The statement "stuff =
OnFindButton1" just makes stuff another reference to that function. To CALL
the function, you have to use parentheses. For example (JUST an example;
this won't actually work):
stuff = OnFindButton1()
The reason this won't actually work is because OnFindButton1 requires two
parameters: an object of type "Form1", and a wx event. Since the procedure
doesn't actually use the "event" parameter, we can supply anything we want.
So, you COULD do this from your mainline code as:
stuff = form1.OnFindButton1(None)
or from inside the class as:
stuff = self.OnFindButton1(None)
But this is not how event procedures are used. The USUAL way to make this
code fire is to press the "Push" button in the window. You don't usually
call them on your own.
If all you want to do is get the text in the control, faking a call to an
event procedure is not the right way. Instead, since you save a copy of the
control in the object, you can refer to the control directly:
print form1.editname.GetValue()
or from inside Form1:
print self.editname.GetValue()
This is the value of a: asdfasdfasdf #......this is what I typed in the
window........
a is of type <type 'string'>
Exit code: 0
#======================================================Although "self.editname.GetValue()" returns a sting inside the method, I
get a function returned
(instead of the string) when I ask the OnFindButton1 to "return
self.editname.GetValue()".How can I get the string returned?
I'm not sure what you're asking here. Where do you want the string to be
returned to? Usually, in a main window like this, you read and use the
contents of the controls only within the methods of the frame's class. You
can use "self.editname.GetValue()" at any time, in any method of Form1, to
get the current contents of the control. You can save it in a file or in a
global, or whatever. You don't have to "capture" it at button-press time.
···
On Fri, 03 May 2002 15:33:39 -0400, Charles Bowman <bowman@acsu.buffalo.edu> wrote:
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.