Search code examples
layoutpysimplegui

How to layout two buttons in verticle by PySimpleGUI?


I use code as below to set layout, I want to two buttons in vertical not in horizontal, what can I do?

layout = [
    [
        sg.Input(readonly=True, expand_x=True, key='Main', disabled_readonly_background_color=sg.theme_input_background_color()),
        sg.Button("Select Folder")
    ],
    [
        sg.Frame("Subfolders & Files", frame_subholders), 
        sg.Button(' ← '), sg.Button(' → '),
        sg.Frame("Selected files", frame_selected)
    ],

enter image description here


Solution

  • As @Jason says, you can use sg.Column. This is a complete working example based on your layout:

    import PySimpleGUI as sg
    
    frame_subholders = [[sg.Multiline()]]
    frame_selected = [[sg.Multiline()]]
    
    column = [
        [sg.Button(' ← ')],
        [sg.Button(' → ')]
    ]
    
    layout = [
        [sg.Input("", readonly=True, expand_x=True),
        sg.Button('Select Folder')],
        [
            sg.Frame("Subfolders & Files", frame_subholders),
            sg.Column(column),
            sg.Frame("Selected files", frame_selected)
        ]]
    
    window = sg.Window('Test', layout)
    
    while True:
        event, values = window.read()
        if event == sg.WINDOW_CLOSED:
            break
        if event == 'Select Folder':
            print('Button pressed')
    
    window.close()
    

    enter image description here