accessing values in wxTextCtrl within sizers

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 (2.97 KB)

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

···

2010/10/4 Norman Elliott <normanelliott@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-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

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')
                                     ^

···

On Oct 4, 9:35 pm, Norman Elliott <normanelli...@gmail.com> wrote:

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
4KViewDownload

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-users+unsubscribe@googlegroups.com
> or visithttp://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

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 OOP in Python: How to Create a Class, Inherit Properties and Methods for guidance.

···

On 04/10/2010 21:35, Norman Elliott wrote:

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-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

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

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

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. 9. Classes — Python 3.13.0 documentation

vbr

···

2010/10/6 linuxonbute <norman.elliott@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.
...

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