From 7a1d010959d5cae134b820da2f190b6c7c0fa0aa Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 22 Aug 2019 13:11:42 -0400 Subject: [PATCH] Chagned center_elements to element_justification --- PySimpleGUI.py | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index d6f8ba04..0cd78d90 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -3190,7 +3190,7 @@ class Frame(Element): def __init__(self, title, layout, title_color=None, background_color=None, title_location=None, relief=DEFAULT_FRAME_RELIEF, size=(None, None), font=None, pad=None, border_width=None, key=None, - tooltip=None, right_click_menu=None, visible=True, center_elements=False): + tooltip=None, right_click_menu=None, visible=True, element_justification='left'): """ :param title: (str) text that is displayed as the Frame's "label" or title :param layout: List[List[Elements]] The layout to put inside the Frame @@ -3207,7 +3207,7 @@ class Frame(Element): :param tooltip: (str) text, that will appear when mouse hovers over the element :param right_click_menu: List[List[Union[List[str],str]]] A list of lists of Menu items to show when this element is right clicked. See user docs for exact format. :param visible: (bool) set visibility state of the element - :param center_elements: (bool) if True all elements inside will be centered + :param element_justification: (str) 'left', 'right', 'center' are valid values """ self.UseDictionary = False @@ -3226,8 +3226,7 @@ class Frame(Element): self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.RightClickMenu = right_click_menu self.ContainerElemementNumber = Window.GetAContainerNumber() - self.CenterEverything = center_elements - + self.ElementJustification = element_justification self.Layout(layout) super().__init__(ELEM_TYPE_FRAME, background_color=background_color, text_color=title_color, size=size, @@ -3333,7 +3332,7 @@ class Tab(Element): """ def __init__(self, title, layout, title_color=None, background_color=None, font=None, pad=None, disabled=False, - border_width=None, key=None, tooltip=None, right_click_menu=None, visible=True, center_elements=False): + border_width=None, key=None, tooltip=None, right_click_menu=None, visible=True, element_justification='left'): """ :param title: (str) text to show on the tab :param layout: List[List[Element]] The element layout that will be shown in the tab @@ -3347,7 +3346,7 @@ class Tab(Element): :param tooltip: (str) text, that will appear when mouse hovers over the element :param right_click_menu: List[List[Union[List[str],str]]] A list of lists of Menu items to show when this element is right clicked. See user docs for exact format. :param visible: (bool) set visibility state of the element - :param center_elements: (bool) if True all elements inside the Tab will be centered + :param element_justification: (str) 'left', 'right', 'center' are valid values """ self.UseDictionary = False @@ -3366,7 +3365,8 @@ class Tab(Element): self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.RightClickMenu = right_click_menu self.ContainerElemementNumber = Window.GetAContainerNumber() - self.CenterEverything = center_elements + self.ElementJustification = element_justification + self.Layout(layout) super().__init__(ELEM_TYPE_TAB, background_color=background_color, text_color=title_color, font=font, pad=pad, @@ -3502,6 +3502,8 @@ class TabGroup(Element): self.ChangeSubmits = change_submits or enable_events self.TabLocation = tab_location self.CenterEverything = False + self.ElementJustification = 'left' + self.Layout(layout) super().__init__(ELEM_TYPE_TAB_GROUP, background_color=background_color, text_color=title_color, font=font, @@ -3851,7 +3853,7 @@ class Column(Element): """ def __init__(self, layout, background_color=None, size=(None, None), pad=None, scrollable=False, - vertical_scroll_only=False, right_click_menu=None, key=None, visible=True, center_elements=False): + vertical_scroll_only=False, right_click_menu=None, key=None, visible=True, element_justification='left'): """ :param layout: List[List[Element]] Layout that will be shown in the Column container :param background_color: (str) color of background of entire Column @@ -3863,7 +3865,7 @@ class Column(Element): :param right_click_menu: List[List[Union[List[str],str]]] A list of lists of Menu items to show when this element is right clicked. See user docs for exact format. :param key: (any) Value that uniquely identifies this element from all other elements. Used when Finding an element or in return values. Must be unique to the window :param visible: (bool) set visibility state of the element - :param center_elements: (bool) if True all elements contained inside will be centered + :param element_justification: (str) 'left', 'right', 'center' are valid values """ self.UseDictionary = False @@ -3881,7 +3883,8 @@ class Column(Element): self.RightClickMenu = right_click_menu bg = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.ContainerElemementNumber = Window.GetAContainerNumber() - self.CenterEverything = center_elements + self.ElementJustification = element_justification + self.Layout(layout) super().__init__(ELEM_TYPE_COLUMN, background_color=bg, size=size, pad=pad, key=key, visible=visible) @@ -4925,7 +4928,7 @@ class Window: alpha_channel=1, return_keyboard_events=False, use_default_focus=True, text_justification=None, no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=False, disable_close=False, disable_minimize=False, right_click_menu=None, transparent_color=None, debugger_enabled=True, - finalize=False, center_elements=False): + finalize=False, element_justification='left'): """ :param title: (str) The title that will be displayed in the Titlebar and on the Taskbar :param layout: List[List[Elements]] The layout for the window. Can also be specified in the Layout method @@ -4960,7 +4963,7 @@ class Window: :param transparent_color: (str) Any portion of the window that has this color will be completely transparent. You can even click through these spots to the window under this window. :param debugger_enabled: (bool) If True then the internal debugger will be enabled :param finalize: (bool) If True then the Finalize method will be called. Use this rather than chaining .Finalize for cleaner code - :param center_elements: (bool) If True then all of the Elements inside will be centered + :param element_justification: (str) 'left', 'right', 'center' are valid values """ self.AutoSizeText = auto_size_text if auto_size_text is not None else DEFAULT_AUTOSIZE_TEXT @@ -5023,7 +5026,7 @@ class Window: self.UniqueKeyCounter = 0 self.DebuggerEnabled = debugger_enabled self.WasClosed = False - self.CenterEverything = center_elements + self.ElementJustification = element_justification if type(title) != str: warnings.warn('Your title is not a string. Are you passing in the right parameters?', UserWarning) if layout is not None and type(layout) not in (list, tuple): @@ -8575,10 +8578,17 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): # ............................DONE WITH ROW pack the row of widgets ..........................# # done with row, pack the row of widgets # tk_row_frame.grid(row=row_num+2, sticky=tk.NW, padx=DEFAULT_MARGINS[0]) - if form.CenterEverything: - anchor = 'n' + + # if form.CenterEverything: + # anchor = 'n' + # else: + # anchor = 'nw' + if form.ElementJustification.lower().startswith('c'): + anchor='n' + elif form.ElementJustification.lower().startswith('r'): + anchor='ne' else: - anchor = 'nw' + anchor='nw' tk_row_frame.pack(side=tk.TOP, anchor=anchor, padx=toplevel_form.Margins[0], expand=row_should_expand, fill=tk.BOTH if row_should_expand else tk.NONE) if form.BackgroundColor is not None and form.BackgroundColor != COLOR_SYSTEM_DEFAULT: @@ -11193,7 +11203,7 @@ def main(): resizable=True, debugger_enabled=False, keep_on_top=True, - center_elements=True, + # icon=r'X:\VMWare Virtual Machines\SHARED FOLDER\kingb.ico' ).Finalize() graph_elem.DrawCircle((200, 200), 50, 'blue')