PySimpleGUI: How to achieve elements/frames/columns to align to the right (and resize) when resizing window

Viewed 5849

I haven't found how to achieve the following:

In the example-code, when resizing the window, the separator in the middle should go to the right, along with the changing of the window-size. The column on the left-hand - with the table in it - should resize and the table also.

What is the general procedure to do those things in PySimpleGui?


import PySimpleGUI as sg



mk = ["irgendwas"]

first_column = [
    [sg.Text("Text:")],
    [sg.Text("Content of Table")],
    [sg.Table(values=[['1','2','3','4'],['1','2','3','4']],headings=['one','two','three','four'],max_col_width=25,
                    # background_color='light blue',
                    auto_size_columns=True,
                    justification='right',
                    num_rows=20,
                    key='-UMSATZTABLE-',
                    row_height=20)],
    [sg.Button('SUBMIT', key="-SUBMIT-")],
    ]

second_column = [[
            sg.Frame(layout=[
                                [sg.Text("BText:"),  sg.InputText(size = (20,1),key="-AKT_BUCHUNGSTEXT-")],
                            ], title='actual:',element_justification='right', pad=(0,0)),
                ],
            [sg.Frame(layout=[
                                [sg.Text("Man Kat:"), sg.Combo(mk, enable_events=True, key='-MANUELLEKATEGORIEN-')],
                            ], title='Aenderung:'),
            ]
]

#col1 = sg.Col(first_column)
#col2 = sg.Col(second_column)



#layout = [[sg.Pane([col1,col2],handle_size=15, orientation='h', background_color='red', show_handle=True, visible=True, key='-PANE-', border_width=0, relief=sg.RELIEF_GROOVE)]]


layout = [
           [sg.Column(first_column),
             sg.VSeperator(pad=(0,0)),
            sg.Column(second_column),
           ]
    ]



window = sg.Window("Umbuchungen", layout,auto_size_text=True,
                   auto_size_buttons=True,resizable=True,grab_anywhere=False,border_depth=5,
                   default_element_size=(15, 1),finalize=True)


window["-UMSATZTABLE-"].expand(True,True)
window["-UMSATZTABLE-"].table_frame.pack(expand=True,fill='both')

while True:
    event, values = window.read()

    if event == "Exit" or event == sg.WIN_CLOSED:
        break
    elif event == "-MONATRET-":
        if str.isdigit(values["-MONAT-"]):
            # k.name as kategorie, substring(u.buchtext,1,45) as buchtext, u.betrag ,valuta, u.pos
            umsatzrows=ga_helper_funcs.get_monthly_revenue(db, values["-MONAT-"])
            #pos,buchtext,valuta,betrag
            positionen = [[i[4], i[1][0:10],i[3],i[2]]  for i in umsatzrows]



            window["-UMSATZTABLE-"].update(positionen)
1 Answers

In order to get the effect that I think you are going for, you need to expand the first column and the table.

col1 = sg.Column(first_column)

layout = [
    [col1,
     sg.VSeperator(pad=(0, 0)),
     sg.Column(second_column),
     ]
]


window = sg.Window("Umbuchungen", layout, auto_size_text=True,
                   auto_size_buttons=True, resizable=True, grab_anywhere=False, border_depth=5,
                   default_element_size=(15, 1), finalize=True)

col1.expand(True, True)

Adding in the col1.expand() is really all you need to see it working, but your table has maximums set for the col width as well, so it may need some more adjustments.

enter image description here

Related