2

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)
nycynik
  • 7,371
  • 8
  • 62
  • 87
Grisalho S.K.
  • 21
  • 1
  • 4

1 Answers1

2

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

nycynik
  • 7,371
  • 8
  • 62
  • 87
  • Ah, thx. I see, I used this method for the table itself (window["-UMSATZTABLE-"].expand(True,True)). Nice. Is there a chance for an event to manipulate the column width while resizing col1 (resizing the window)? – Grisalho S.K. Mar 01 '21 at 15:08
  • I'm not sure, maybe ask another question - I'm not sure if there is an event for the column resize. I've only used `auto_size_columns` and `max_col_width` to set column sizes, if you make the max col width large, it will resize them for you. – nycynik Mar 02 '21 at 07:04