Skip to content

Commit ec4db9a

Browse files
authored
Merge pull request #31 from molssi-seamm/dev
Return the width of aligned labels
2 parents c3fa596 + 98ec794 commit ec4db9a

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

HISTORY.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
=======
22
History
33
=======
4-
4+
2024.7.21 -- Return the width of aligned labels
5+
* The align_labels procedure now returns the width of the labels. This is useful for
6+
laying out indented widgets.
7+
58
2024.5.1 -- Enhancement to ScrolledColumns
69
* Added optional separator columns for dividing sections of the table.
710

seamm_widgets/labeled_widget.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
}
4141

4242

43-
def align_labels(widgets, sticky=None):
43+
def align_labels(widgets, sticky=tk.E):
4444
"""Align the labels of a given list of widgets"""
45-
if len(widgets) <= 1:
46-
return
45+
if len(widgets) == 0:
46+
return 0
4747

4848
widgets[0].update_idletasks()
4949

@@ -56,10 +56,13 @@ def align_labels(widgets, sticky=None):
5656

5757
# Adjust the margins for the labels such that the child sites and
5858
# labels line up.
59-
for widget in widgets:
60-
if sticky is not None:
61-
widget.label.grid(sticky=sticky)
62-
widget.grid_columnconfigure(0, minsize=max_width)
59+
if len(widgets) > 1:
60+
for widget in widgets:
61+
if sticky is not None:
62+
widget.label.grid(sticky=sticky)
63+
widget.grid_columnconfigure(0, minsize=max_width)
64+
65+
return max_width
6366

6467

6568
class LabeledWidget(ttk.Frame):

0 commit comments

Comments
 (0)