accessing values in wxTextCtrl within sizers

3 views
Skip to first unread message

Norman Elliott

unread,
Oct 4, 2010, 4:35:20 PM10/4/10
to wxpytho...@googlegroups.com
Hi,

I am in trouble again! This time  with the syntax for getting  values from a wxTextCtrl.

If I run my code from a console I get the expected output from

print inputTxtOne.GetValue() in the code attached.

Problem is I want, instead, to get that information into a variable which I can check is
in the range which is acceptable and then write it to my device ( an iButton thermochron)

The code is a very cut down version of what I already have.

if you look at the code you will see I have tried several ideas as to what the correct syntax is
but none of them worked.  They are:
#            mins=inputTxtOne.GetValue()
#            mins=self.inputTxtOne.GetValue()
#            mins=self.panel.inputTxtOne.GetValue()
#            mins=panel.inputTxtOne.GetValue()
#            mins=MyForm.panel.inputTxtOne.GetValue()
#            mins=MyForm.inputTxtOne.GetValue()

I cannot see why the print statement works but the others don't.

No doubt I am being dense as usual but I do hope someone can explain how to work it out.
a0.py

Vlastimil Brom

unread,
Oct 4, 2010, 4:57:39 PM10/4/10
to wxpytho...@googlegroups.com
2010/10/4 Norman Elliott <norman...@gmail.com>:
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en

Hi,
if you change all occurences of
inputTxtOne
in the code to
self.inputTxtOne
the second variant should work:
mins=self.inputTxtOne.GetValue()

also note the typo in case:
wx.TExtCtrl >> wx.TextCtrl

hth,
vbr

linuxonbute

unread,
Oct 4, 2010, 4:58:31 PM10/4/10
to wxPython-users
I copied a slight fault in the attached code:-
line 15 is inputTxtOne = wx.TExtCtrl(self.panel,
wx.ID_ANY,'1')
and it should be inputTxtOne = wx.TextCtrl(self.panel,
wx.ID_ANY,'1')
^
>  a0.py
> 4KViewDownload

linuxonbute

unread,
Oct 4, 2010, 5:02:42 PM10/4/10
to wxPython-users
Great thanks. Did as you suggested and away we go.

On Oct 4, 9:57 pm, Vlastimil Brom <vlastimil.b...@gmail.com> wrote:
> 2010/10/4 Norman Elliott <normanelli...@gmail.com>:
>
>
>
> > Hi,
>
> > I am in trouble again! This time  with the syntax for getting  values from a
> > wxTextCtrl.
>
> > If I run my code from a console I get the expected output from
>
> > print inputTxtOne.GetValue() in the code attached.
>
> > Problem is I want, instead, to get that information into a variable which I
> > can check is
> > in the range which is acceptable and then write it to my device ( an iButton
> > thermochron)
>
> > The code is a very cut down version of what I already have.
>
> > if you look at the code you will see I have tried several ideas as to what
> > the correct syntax is
> > but none of them worked.  They are:
> > #            mins=inputTxtOne.GetValue()
> > #            mins=self.inputTxtOne.GetValue()
> > #            mins=self.panel.inputTxtOne.GetValue()
> > #            mins=panel.inputTxtOne.GetValue()
> > #            mins=MyForm.panel.inputTxtOne.GetValue()
> > #            mins=MyForm.inputTxtOne.GetValue()
>
> > I cannot see why the print statement works but the others don't.
>
> > No doubt I am being dense as usual but I do hope someone can explain how to
> > work it out.
>
> > --
> > To unsubscribe, send email to wxPython-user...@googlegroups.com
> > or visithttp://groups.google.com/group/wxPython-users?hl=en

Steven Sproat

unread,
Oct 31, 2010, 8:21:14 PM10/31/10
to wxpytho...@googlegroups.com
It's helpful to post the error you're getting. I'm guessing at
AttributeError which indicates a problem outside of wx.
Not to sound nasty here, but it doesn't seem like you "get" the concept
of OO programming. Check out
http://diveintopython.org/object_oriented_framework/index.html for guidance.

--
Steven Sproat, BSc
http://www.whyteboard.org/

linuxonbute

unread,
Oct 5, 2010, 6:26:43 PM10/5/10
to wxPython-users

> Not to sound nasty here, but it doesn't seem like you "get" the concept
> of OO programming. Check outhttp://diveintopython.org/object_oriented_framework/index.htmlfor guidance.

No offence taken, you are right I don't 'get' this yet. I have only
been trying this out recently and have no prior experience with any
sort of OO programming or wxpython and little with python. I have
mainly done php/mysql stuff.
I have several reasons for doing this, one being that I want to use an
ibutton ( thermochron ) as part of a bigger project. Another is to
learn about OO and also as some others have said that they have not
been able to use these I would like to give the code to help them.

I had a look at owfs to work with the ibutton and, after correcting a
bug in the owfs code, wrote some very simple command line code to set
one up and a bit of python to get data from it. I am writing this code
to make it a single program to do all the bits through a GUI.

I have had a look at the site you suggested but much of it is still
going over my head at present.

I am still at a loss to understand why :

print inputTxtOne.GetValue() worked but not mins =
inputTxtOne.GetValue().

I am guessing that it must have something to do with where the output
goes to.

At least with the help here I have got all the code written and
working except the part where it programs the ibutton. I expect I will
finish that soon. Then I will have go at getting data out and
displaying it.

Thanks for all the help everyone.

Norman


Vlastimil Brom

unread,
Oct 5, 2010, 6:51:22 PM10/5/10
to wxpytho...@googlegroups.com
2010/10/6 linuxonbute <norman....@gmail.com>:
> ...

> I am still at a loss to understand why :
>
> print inputTxtOne.GetValue() worked but not mins =
> inputTxtOne.GetValue().
>
> I am guessing that it must have something to do with where the output
> goes to.
> ...

Basically, there are different scopes of the names (variables) used,
assigning mins = ... only makes it accessible under that name in the
current scope - in this case - the respective function (the same for
inputTxtOne). If the names belong to different scopes, they don't
"see" each other.
Using self.min ... within the class methods makes these names belong
to the class and makes them accessible across multiple methods of that
class instance (as self is passed as the first parameter of the
methods).
see e.g. http://docs.python.org/tutorial/classes.html

vbr

C M

unread,
Oct 5, 2010, 7:26:04 PM10/5/10
to wxpytho...@googlegroups.com
> I am still at a loss to understand why :
>
> print inputTxtOne.GetValue() worked but not mins =
> inputTxtOne.GetValue().

Both of these lines will work in wxPython. The problem you had is a
Python issue, which is that you were assigning what mins was in one
scope, but expecting to be able to print what mins was in a
*different* scope--but information like that stays in its scope (or
"namespace") only. In this case, "scope" means in different
functions. That's it. By prepending "self." to mins when you assign
it, you are telling it to be a available to the whole class, since
"self" refers to to that instance of the class. (This dot notation is
used to show hierarchy of objects, with each dot showing separating a
parent from child)

In a nutshell: if you want names to stay put within their functions,
don't put "self." in front of them (this should be the default). But
if you want to share the name among different functions, you can
either pass the name in a function call, like:

self.NameScrambler(start_name)

or you can make the name globally available by putting "self." in
front of it, like:

self.start_name

Che

Ray Pasco

unread,
Oct 6, 2010, 1:33:58 PM10/6/10
to Wxpython Users
Have a look at the demo app named DUAL_CONTROL_CLASS_2.PY  found at :

     BoxSizerFromTheGroundUp/NestedBoxSizers

This will show you have to extract the control variables created from a class instantiation. You could, instead, write a method in the class definition simply to extract the controls' values rather than the control variables, themselves.

Controls are usually instantiated (created) and assigned to variables. Once this is done it makes no difference whether the app is kicked off from the command line, a script file or from the OS's GUI.

Ray Pasco

C M

unread,
Oct 6, 2010, 5:01:43 PM10/6/10
to wxpytho...@googlegroups.com
I'm top posting here because what I am writing about doesn't have
anything to do with the content...but with Ray's method of responding.

I read this list by getting emails and Ray, I've noticed that some but
not all of your responses arrive to my inbox as a separate thread
instead of in the original thread. Wasn't there a discussion about
this issue some time back? In any case, would you be interested
altering what you are doing so as to not do that? I think it is a lot
better for the quality of the archive and the day to day reading of
the list for threads to remain intact.

Thanks,
Che

linuxonbute

unread,
Oct 6, 2010, 5:27:25 PM10/6/10
to wxPython-users


On Oct 6, 6:33 pm, Ray Pasco <pas...@verizon.net> wrote:
> Have a look at the demo app namedDUAL_CONTROL_CLASS_2.PY  found at :
Thanks Ray,
Have had a look and it makes more sense now. Still a lot more reading
to do :<)
norman

Mike Driscoll

unread,
Oct 7, 2010, 9:50:04 AM10/7/10
to wxPython-users
His stuff tends to look right in the web interface. Weird...

- Mike

Ray Pasco

unread,
Oct 7, 2010, 1:11:45 PM10/7/10
to wxPython-users
There was a thread concerning exactly this issue. It is due to a bug
in Gmail. When I send a regular email Gmail *sometimes* screws up
figuring out that it should be added to the end of an existing thread.
I only send an email when I also want to send an attachment. Most
times this does not happen, but success and failure are totally
unpredictable. I would have thought Google Gmail staff would be adept
enough to have already fixed this obvious bug when email originates
from a Thunderbird client.

I'll use my Gmail account to respond with attachments from now on.

Ray

Cody Precord

unread,
Oct 7, 2010, 1:36:52 PM10/7/10
to wxpytho...@googlegroups.com
Hi,

I would suggest that if you would like to participate in discussions
that you change your subscription settings to read messages as Email
(this is a mailing list after all) so you can properly Reply to them
from your inbox. Goto
(http://groups.google.com/group/wxpython-users/subscribe) and check
the "Email" radio button.

The problem isn't that google is messing up it just that you are
sending a new email with the same title instead of replying to the
original message. So as far as the world is concerned you have sent a
brand new email that is not part of the original message thread since
the heading data in your email doesn't contain the reply header from
the previous message(s).


Cody

Ray Pasco

unread,
Oct 8, 2010, 12:23:53 PM10/8/10
to wxPython-users
> The problem isn't that google is messing up it just that you are
> sending a new email with the same title instead of replying to the
> original message. So as far as the world is concerned you have sent a
> brand new email that is not part of the original message thread since
> the heading data in your email doesn't contain the reply header from
> the previous message(s).
>
> Cody

Yes, Google Groups/Gmail is messing up.

I have always had the "Digest Email" radio button selected to avoid
getting 26 separate emails each day. If I click the "Reply" button
from the web page I can not attach any files since the web pages do
not not have this capability. I must use a separate email program,
client or web-based using the thread's title as the email's Subject
line.

I had been using Thunderbird to reply with file attachments rather
than Gmail. The Google Groups email doesn't always properly parse
email headers from Thunderbird even though the Subject line is
identical, therefore correct. This is the one and only cause of the
thread reply goof-ups.

I will use Gmail in the future to post my replies that have attached
files.

Ray

Cody Precord

unread,
Oct 8, 2010, 12:53:43 PM10/8/10
to wxpytho...@googlegroups.com
Hi,

On Fri, Oct 8, 2010 at 11:23 AM, Ray Pasco <pasco...@gmail.com> wrote:
>> The problem isn't that google is messing up it just that you are
>> sending a new email with the same title instead of replying to the
>> original message. So as far as the world is concerned you have sent a
>> brand new email that is not part of the original message thread since
>> the heading data in your email doesn't contain the reply header from
>> the previous message(s).
>>
>> Cody
>
> Yes, Google Groups/Gmail is messing up.
>
> I have always had the "Digest Email" radio button selected to avoid
> getting 26 separate emails each day. If I click the "Reply" button
> from the web page I can not attach any files since the web pages do
> not not have this capability. I must use a separate email program,
> client or web-based using the thread's title as the email's Subject
> line.

That is the problem, you cannot reply to individual messages by using
the digest. The digest is one email with its own header. The digest is
mostly for people that just want to read up and follow whats going on
and not participate.

You need to receive the original individual email messages so that you
can reply to them and preserve the message threading.

Google groups may try to make the threading work by checking the
message title but that is not a standard behavior of email.


Anyway, this is way OT so this will be my last reply

Cody

Ray Pasco

unread,
Oct 9, 2010, 1:22:41 PM10/9/10
to wxPython-users

> That is the problem, you cannot reply to individual messages by using
> the digest. The digest is one email with its own header. The digest is
> mostly for people that just want to read up and follow whats going on
> and not participate.
>
> Cody

This particular thread from the Digest email brings up the web page:

http://groups.google.com/group/wxpython-users/browse_thread/thread/6243a4881acfe802

Each thread topic page has a Reply button at the bottom of each entry.

Ray
Reply all
Reply to author
Forward
0 new messages