Justification setting for Input elements.... Finally can make tables! Demo fo tables

This commit is contained in:
MikeTheWatchGuy 2018-09-06 23:17:40 -04:00
parent 405bcf7cbc
commit ac44b5bdaa
2 changed files with 29 additions and 2 deletions

19
Demo_Table_Simulation.py Normal file
View File

@ -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()

View File

@ -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('<Return>', element.ReturnKeyHandler)
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
element.TKEntry.configure(background=element.BackgroundColor)