<!--/*SC*/DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"/*EC*/-->
<html><head><title></title><style type="text/css"><!--body{padding:1ex;margin:0px;font-family:sans-serif;font-size:small;}a[href]{color:-moz-hyperlinktext !important;text-decoration:-moz-anchor-decoration;}blockquote{margin:0;border-left:2px solid #144fae;padding-left:1em;}blockquote blockquote{border-color:#006312;}blockquote blockquote blockquote{border-color:#540000;}--></style></head><body><div style="font-family: Arial; font-size: medium;" dir="ltr"><div>I'm experimenting with geometry layouts and would like to know if its possible to line up a Label and an Entry widget (in the same horizontal line) and have the Label widget right align to the Entry widget. I know I can do this via grid, but I'm wondering if this is possible via pack.</div>
<div>&nbsp;</div>
<div>Here's the 1 line layout I'm trying to achieve:</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp; [Label] [Entry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]</div>
<div>^^^</div>
<div>Where the ^^^ indicates leading space due to right alignment of the label against its Entry.</div>
<div>&nbsp;</div>
<div>Listed below is my test code. I've tried using Tkinter's Label and ttk's Label. I've tried using anchor, justify, and fill in various combinations without success. One interesting observation: the ttk Label widget always seems to align left in the scenario below while I can get the Tkinter Label widget to center or left align, but never right align.</div>
<div>&nbsp;</div>
<div>Perhaps I'm confused about when to use justification vs. alignment to achieve my goal?</div>
<div>&nbsp;</div>
<div>Your thoughts appreciated!</div>
<div>&nbsp;</div>
<div>import Tkinter as tk<br>
import ttk<br>
<br>
root = tk.Tk()<br>
frame = tk.Frame( root )</div>
<div>&nbsp;</div>
<div>parent = frame<br>
label = tk.Label( parent )</div>
<div>&nbsp;</div>
<div># note that I'm explictly setting width to create an environment for alignment or justification<br>
label.config( text='Password', width=20, justify='right' )<br>
label.pack( side='left', anchor='e', padx=4, pady=4 )<br>
entry = ttk.Entry( parent )<br>
entry.pack( side='left', anchor='w', fill='x', expand=True, padx=4, pady=4 )<br>
frame.pack( side='top', anchor='n', fill='x', expand=True, padx=4, pady=4 )</div>
<div>&nbsp;</div>
<div>root.mainloop()</div>
<div>&nbsp;</div>
<div>Malcolm</div></div></body></html>