Skip to content

Commit

Permalink
Return the width of aligned labels
Browse files Browse the repository at this point in the history
    * The align_labels procedure now returns the width of the labels. This is useful for laying out indented widgets.
  • Loading branch information
paulsaxe committed Jul 21, 2024
1 parent c3fa596 commit 98ec794
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
=======
History
=======

2024.7.21 -- Return the width of aligned labels
* The align_labels procedure now returns the width of the labels. This is useful for
laying out indented widgets.

2024.5.1 -- Enhancement to ScrolledColumns
* Added optional separator columns for dividing sections of the table.

Expand Down
17 changes: 10 additions & 7 deletions seamm_widgets/labeled_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
}


def align_labels(widgets, sticky=None):
def align_labels(widgets, sticky=tk.E):
"""Align the labels of a given list of widgets"""
if len(widgets) <= 1:
return
if len(widgets) == 0:
return 0

widgets[0].update_idletasks()

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

# Adjust the margins for the labels such that the child sites and
# labels line up.
for widget in widgets:
if sticky is not None:
widget.label.grid(sticky=sticky)
widget.grid_columnconfigure(0, minsize=max_width)
if len(widgets) > 1:
for widget in widgets:
if sticky is not None:
widget.label.grid(sticky=sticky)
widget.grid_columnconfigure(0, minsize=max_width)

return max_width


class LabeledWidget(ttk.Frame):
Expand Down

0 comments on commit 98ec794

Please sign in to comment.