[Tkinter-discuss] OptionMenu text justification
jmcmonagle at velseis.com
Mon May 31 01:12:05 CEST 2010
Gary Scorby wrote:
> I’m new to Tkinter. I need a drop down box to display a selection list
> to an end user. It appears the best option for this is “OptionMenu” (If
> not, please suggest other options). I have it working like we want
> except for one thing, after selecting something from the list and
> closing the list, the text is centered in the window. We have some very
> long lines of text to choose from. When the choice is made we would
> like the chosen text to be left justified in the window. I’ve tried
> ever option I can find, but the text remains centered. Any assistance
> will be appreciated.
In what widget are you displaying the text ? Label, Entry, Text ?
For example, the following code displays two labels with varying lengths
of text, aligned to the left:
from Tkinter import *
r = Tk()
t1 = 'Short text'
t2 = 'Long line of meaningless text to illustrate problem'
l1 = Label(r, text=t1)
l2 = Label(r, text=t2)
Now, if you wish to restrict the text to some horizontal distance and
keep it left justified, you would use wraplength=distance, justify=LEFT
as extra options to the Label widget.
I hope this provides some assistance.
More information about the Tkinter-discuss