[Tutor] Tkinter widget config options help
Scott Walkup
bwalkup@compuserve.com
Thu, 19 Jul 2001 14:20:25 -0400
Hello everyone!
I've been checking out the chapter in Programming Python 2nd Edition
about GUI programming with Tkinter. While still on the early examples
I've come across a rather embarissing/annoying bug somewhere in my
python setup.
One the first few examples of GUI programming specificaly dealing with
passing config options to the Tkinter module:
from Tkinter import *
Label(text='Hello GUI World!').pack(expand=YES, fill=BOTH)
mainloop()
spit out errors about NameError YES not being defined.
(well actualy now that works,*boggle* but another way I tried to setup
this script was:
#!/usr/bin/python
import Tkinter
widget = Tkinter.Label(None, text='Hello GUI world!')
widget.pack(fill="both",expand=1)
widget.mainloop()
(I set it up as an executable for linux, so ingore the
#!/usr/bin/python)
The program this way works, but note that both config options, fill and
expand have different settings that want the book said I could use
(meaning YES instead of 1 and BOTH instead of passing it as a string,
not a variable). But if I try using the books example of passing
variables, python calls me stupid and says YES (and if I switch it
around) and BOTH are not defined.
I went and hunted down my Tkinter.py and searched in the code there
(Thanks to python its easy to read and not be completely confused
sometimes) and found I could pass 1 for expand and by
experimentation I figured out I could use "both" to get what I wanted
done.
So anyway I also found out where all these variables where hiding from
me, in Tkconstants.py, and I was able to verify that the variables I
needed where in there, and also that Tkinter.py was calling that file,
but somehow in all this weirdness, my script never seems to know that
they do exist *grumble*.
I've searched the newgroups, mailing list archives and checked out all
the relevant FAQ's I could find for this problem, do I just have a
problem in the code I was creating? (I could have sworn the books
example didnt work last night)
Another thing, I also checked out the Tkinter FAQ for unix and it talked
of trying out
import Tkinter
Tkinter._test()
and that does work. Ugh.
Any help is appreciated, I'm sure I'm missing something obvious in my
code, or maybe python just doesnt want to work with me today.
TIA!