[Tkinter-discuss] OptionMenu text justification

Gary Scorby Gary.Scorby at harlandfs.com
Tue Jun 1 17:15:31 CEST 2010

I guess I didn't explain this very well.

I attempting to use Tkinter OptionMenu as a dropdown list.  After picking the desired text in the dropdown list the text is centered in the window.  I would like it to be left justified.  Nothing I have tried has been successful.  I am not talking about the label.  I am not talking about text entered by hand.  I am talking about the text in the dropdown list after a selection is made from that list.



-----Original Message-----
From: John McMonagle [mailto:jmcmonagle at velseis.com] 
Sent: Sunday, May 30, 2010 4:12 PM
To: Gary Scorby
Cc: tkinter-discuss at python.org
Subject: Re: [Tkinter-discuss] OptionMenu text justification

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 mailing list