Config options on Tkinter Label Widget

Sheila King sheila at spamcop.net
Wed Jul 4 22:12:35 EDT 2001


Problem solved.

What someone pointed out to me, is that the text is anchored to the
left, but the label widget is only as wide as the text, and is being
centered at the top of the root window.

So, I can see this better if I color the background of the label widget,
like this:
Directions.config(anchor=W,bg='yellow',width=70)

Also, I should solve this dilemma, probably by using the expand and fill
options when I pack the label. Something like this:
Directions.pack(expand=1,fill=X)

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/

On Thu, 05 Jul 2001 01:13:39 GMT, Sheila King <sheila at spamcop.net> wrote
in comp.lang.python in article
<anf7kt4edeq12n4kb7hjdd73jjhnck2bco at 4ax.com>:

:I'm trying my hand at a bit of Tkinter programming. I must say, the
:discussion in Mark Lutz' Programming Python, 2nd ed, is really
:excellent.
:
:Anyhow, I liked the suggestion in Chun's Core Python Programming for one
:of the exercises: "Label and Entry Widgets and Python I/O: Create a GUI
:application that provides and Entry field where the suer can provide the
:name of a text file. Open the file and read it, displaying its contents
:in a Label."
:
:So, I'm just starting out on the exercise, and I decided to mess around
:a bit with the look and feel of the application. (I've also snagged a
:local copy of Lundh's Tkinter reference and the Tkinter Life
:Preserver...so I think I have ample reference material.)
:
:So, here is my code so far:
:--------------------------------------------------------------
:
:from Tkinter import *
:
:root = Tk()
:Directions = Label(root, text ='Enter name of File to Open:')
:Directions.config(anchor=W)
:inputBox = Entry(root, width=80)
:
:Directions.pack()
:inputBox.pack()
:mainloop()
:--------------------------------------------------------------
:
:Now, notice the line where I am trying to configure on Directions the
:positioning of the text in the label:
:Directions.config(anchor=W)
:
:From reading Lundh's reference, I thought that this would position the
:text all the way to the left of the label.
:
:However, it remains centered.
:
:Why isn't it moving to the left? What do I need to do to get that
:effect?
:
:Thanks,




More information about the Python-list mailing list