From ac44b5bdaa04463834e5b7aaa91c35fa08098f88 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Thu, 6 Sep 2018 23:17:40 -0400 Subject: [PATCH] Justification setting for Input elements.... Finally can make tables! Demo fo tables --- Demo_Table_Simulation.py | 19 +++++++++++++++++++ PySimpleGUI.py | 12 ++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 Demo_Table_Simulation.py diff --git a/Demo_Table_Simulation.py b/Demo_Table_Simulation.py new file mode 100644 index 00000000..b61b263c --- /dev/null +++ b/Demo_Table_Simulation.py @@ -0,0 +1,19 @@ +import PySimpleGUI as sg + +def TableSimulation(): + """ + Display data in a table format + """ + # sg.ChangeLookAndFeel('Dark') + + layout = [[sg.T('Table Using Combos and Input Elements', font='Any 18')]] + + for i in range(20): + inputs = [sg.In('{}{}'.format(i,j), size=(8, 1), pad=(1, 1), justification='right') for j in range(10)] + inputs = [sg.Combo(('Customer ID', 'Customer Name', 'Customer Info')), *inputs] + layout.append(inputs) + + sg.FlexForm('Table').LayoutAndRead(layout) + + +TableSimulation() \ No newline at end of file diff --git a/PySimpleGUI.py b/PySimpleGUI.py index e3f31fdf..393a690a 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -261,7 +261,8 @@ class Element(): # Input Class # # ---------------------------------------------------------------------- # class InputText(Element): - def __init__(self, default_text ='', scale=(None, None), size=(None, None), auto_size_text=None, password_char='', background_color=None, text_color=None, do_not_clear=False, key=None, focus=False, pad=None): + def __init__(self, default_text ='', scale=(None, None), size=(None, None), auto_size_text=None, password_char='', + justification=None, background_color=None, text_color=None, do_not_clear=False, key=None, focus=False, pad=None): ''' Input a line of text Element :param default_text: Default value to display @@ -277,6 +278,7 @@ class InputText(Element): fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR self.Focus = focus self.do_not_clear = do_not_clear + self.Justification = justification super().__init__(ELEM_TYPE_INPUT_TEXT, scale=scale, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad) @@ -2251,7 +2253,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form): element.TKStringVar = tk.StringVar() element.TKStringVar.set(default_text) show = element.PasswordCharacter if element.PasswordCharacter else "" - element.TKEntry = tk.Entry(tk_row_frame, width=element_size[0], textvariable=element.TKStringVar, bd=border_depth, font=font, show=show) + if element.Justification is not None: + justification = element.Justification + else: + justification = DEFAULT_TEXT_JUSTIFICATION + justify = tk.LEFT if justification == 'left' else tk.CENTER if justification == 'center' else tk.RIGHT + anchor = tk.NW if justification == 'left' else tk.N if justification == 'center' else tk.NE + element.TKEntry = tk.Entry(tk_row_frame, width=element_size[0], textvariable=element.TKStringVar, bd=border_depth, font=font, show=show, justify=justify) element.TKEntry.bind('', element.ReturnKeyHandler) if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT: element.TKEntry.configure(background=element.BackgroundColor)