textvariable help

S

swisscheese

I must be missing something basic.
Can anyone explain why 'A' does not show on the entry widget?

import Tkinter
root = Tkinter.Tk()
class Col:
Rows = [0]
def __init__(self):
Frame = Tkinter.Frame(root);
Frame.pack (side='left')
self.Rows[0] = Tkinter.StringVar();
Tkinter.Entry(Frame,textvariable=self.Rows[0]).pack ();
X = Col()
# X.Rows[0].set ('A') # 'A' displays in Entry this way
Y = Col()
X.Rows[0].set ('A') # Why not also this way?
Y.Rows[0].set ('B')
root.mainloop()
 
F

Fredrik Lundh

swisscheese said:
I must be missing something basic.
Can anyone explain why 'A' does not show on the entry widget?

import Tkinter
root = Tkinter.Tk()
class Col:
Rows = [0]
def __init__(self):
Frame = Tkinter.Frame(root);
Frame.pack (side='left')
self.Rows[0] = Tkinter.StringVar();
Tkinter.Entry(Frame,textvariable=self.Rows[0]).pack ();
X = Col()
# X.Rows[0].set ('A') # 'A' displays in Entry this way
Y = Col()
X.Rows[0].set ('A') # Why not also this way?
Y.Rows[0].set ('B')
root.mainloop()

Rows is a class variable, and since you're modifying it in place, Rows[0] will
always be set to the most recently created Entry widget.

what is it you're trying to do here ?

</F>
 
S

swisscheese

Thanks for the quick reply. With your reply and another tutorial I get
it now. I needed "self.Rows = ..." in the constructor. I find myself
wasting a lot of time with poor python docs. Whatever time Python is
supposed to save I'm losing so far in looking up things. I suppose that
will change as I get past the learning curve. Are you aware of any good
docs on python that make it easy to find things?
 
F

Fredrik Lundh

swisscheese said:
Thanks for the quick reply. With your reply and another tutorial I get
it now. I needed "self.Rows = ..." in the constructor. I find myself
wasting a lot of time with poor python docs. Whatever time Python is
supposed to save I'm losing so far in looking up things. I suppose that
will change as I get past the learning curve. Are you aware of any good
docs on python that make it easy to find things?

just curious, but what documentation told you to use a class variable
in the way you did ?

</F>
 
J

James Stroud

swisscheese said:
Thanks for the quick reply. With your reply and another tutorial I get
it now. I needed "self.Rows = ..." in the constructor. I find myself
wasting a lot of time with poor python docs.

I have found the standard library documentation amazingly well written:

http://www.python.org/doc/

Whatever time Python is
supposed to save I'm losing so far in looking up things. I suppose that
will change as I get past the learning curve.

Python will save you a lot of time when you come back to your code 6
months later and when you begin to get some competence at the more
esoteric aspects of python, like generators, closures, and magic methods.
Are you aware of any good
docs on python that make it easy to find things?

It depends on your task. Jumping into GUI programming without a solid
grasp of the language you are writing in can be frustrating. In fact
jumping into GUI programming at all can be frustrating.

I learnt from Learning Python by O'Reilly. Beyond that I highly
recommend Python Programming. I especially recommend chapters 2, 3, 6,
7, and 8 of the latter. If you have the time, try to get through as much
of both of those as you can. Beyond that, you may want to keep a copy of
Python in a Nutshell by your keyboard. I use the classic Python
Essential Reference, which is now pretty dated.

If you have not worked through a tutorial on python basics, you should
really stop what you are doing and spend a few hours doing that. It will
make you much more pleased with the language.

James
 
S

swisscheese

Thanks - actually I have some of those books on the way from amazon.
The first couple of days with a new language are always the hardest!
 

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,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top