How to Align Multiple Frames in Pysimplegui

Asked 1 years ago, Updated 1 years ago, 373 views

https://mebee.info/2022/02/04/post-34359/
Using the above site as a reference, we created a layout consisting of multiple frames.

import PySimpleGUI as sg
sg.theme ('LightGreen')
l1 = [      
        [sg.Button('A', size=(5,1)), sg.Button('B', size=(5,1)))],
        [sg.Button('C', size=(5,1)), sg.Button('D', size=(5,1)))],
        [sg.Button('E', size=(5,1)), sg.Button('F', size=(5,1)))],
        [sg.Button('E', size=(5,1)), sg.Button('F', size=(5,1)))],
        [sg.Button('E', size=(5,1)), sg.Button('F', size=(5,1)))],
        [sg.Button('E', size=(5,1)), sg.Button('F', size=(5,1)))]
    ]

l2 = [        
        [sg.Button('A', size=(5,1)), sg.Button('B', size=(5,1)))],
        [sg.Button('C', size=(5,1)), sg.Button('D', size=(5,1)))]
    ]

layout = [[sg.Frame('Group1', l1), sg.Frame('Group2', l2)]]

window=sg.Window('title', layout, size=(300,300))
while True:
    event, values = window.read()
    if event==sg.WIN_CLOSED:
        break
window.close()

If the number of elements in each frame is different, there is a problem that is centered.
Is there a good way to make it better?

I think it is possible to specify pad as one of the methods, but
It's a bit complicated to calculate and specify all the positions, up, down, left and right, so please let me know if there is a better method.
https://mebee.info/2022/01/01/post-34174/

layout

python

2023-02-01 21:09

1 Answers

Why don't you add the following sentence to the next line of layout=?

layout[0][1].VerticalAlignment="top"


2023-02-02 02:09

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.