How to get or set the text of a textfield?

A

Anthony Papillion

Hi Everyone,

So I've built a UI with Glade and have loaded it using the standard
Python code. In my UI, I have a textfield called txtUsername. How do I
get and set the text in this field from my Python code?

Thanks!
Anthony

--
Anthony Papillion
Advanced Data Concepts
Get real about your software/web development and IT Services
Phone: (918) 919-4624

Does your business need to reduce its phone bill? I can help!
Email me and ask me how!
 
J

John Gordon

In said:
So I've built a UI with Glade and have loaded it using the standard
Python code. In my UI, I have a textfield called txtUsername. How do I
get and set the text in this field from my Python code?

I don't know anything about Glade, so I can't answer your question
definitively. However, as a general rule, you can use the dir() builtin
function to see what methods are defined by an object.

So, assuming you have access to an interactive shell within your Glade
environment, you can do this:

dir(txtUsername)

and it will print a list of methods that are defined by that object.
Hopefully one of them will be called something helpful like set_text()
or set_property(). Once you know the method name, you might try a Google
search to determine the exact usage and arguments.
 
A

Anthony Papillion

I don't know anything about Glade, so I can't answer your question
definitively. However, as a general rule, you can use the dir() builtin
function to see what methods are defined by an object.

Hi John,

Thanks for the input and it looks like it's pretty simple. Basically, I
can access the properties of objects like:

self.objectname.property_or_method()

So, to solve my question, I'd just use:

self.txtUsername.set_text('Whatever I want')

or

enteredText = self.txtUsername.get_text()

Pretty simple and this actually solves ALL of my Glade problems. I'm
excited.

Thanks for the direction!

Anthony
 
A

Adam Tauno Williams

field.get_text()
field.set_text(value)

and it will print a list of methods that are defined by that object.
Hopefully one of them will be called something helpful like set_text()
or set_property(). Once you know the method name, you might try a Google
search to determine the exact usage and arguments.

-1 -1 -1 Do not "google" [search the Internet] for solutions to pyGtk
problems. That is just a confusing waste of time. Use the *excellent*
and well-linked documentation:

<http://pygtk.org/docs/pygtk/>
<http://faq.pygtk.org/index.py?req=index>

The FAQ is extensive and really does cover a lot of the common
questions. Also there is a list specifically for pygtk questions:

<http://www.daa.com.au/mailman/listinfo/pygtk>

Google, or Bing, or even DuckDuckGo, are *not* your friends. They are
enormous and inefficient time-sinks. They are a *BAD* way to solve
problems. Use the documentation.
 
J

John Gordon

In said:
Google, or Bing, or even DuckDuckGo, are *not* your friends. They are
enormous and inefficient time-sinks. They are a *BAD* way to solve
problems. Use the documentation.

One would hope that a Google search might lead to the documentation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,037
Latest member
MozzGuardBugs

Latest Threads

Top