Andrea Mele
Andrea Mele

Reputation: 63

PySimpleGui - Nesting Frames

enter image description here

How can I achieve nesting frames in this way. One left Frame (Frame 1), one Right (Frame 2). With another Frame (Frame 3) nested inside and but under the Left Frame contents?

Does the formatting allow for this?

Upvotes: 3

Views: 4542

Answers (1)

Jason Yang
Jason Yang

Reputation: 13057

From outside to inside for your design

  • Left Frame1, right Frame2 in main layout
layout = [
    [sg.Frame("Frame1", ...), sg.Frame("Frame2", ...)],
]
  • Top Frame 4, bottom Frame 3 in Frame1
layout = [
    [sg.Frame("frame 4", ...],
    [sg.Frame("Frame 3", ...],
]
  • Again, Left Frame 5, right Frame 6 in Frame 4
layout = [
    [sg.Frame("Frame 5", ...), sg.Frame("Frame 6", ...)],
]

That's all !

import PySimpleGUI as sg

def blank_frame():
    return sg.Frame("", [[]], pad=(5, 3), expand_x=True, expand_y=True, background_color='#404040', border_width=0)

sg.theme('DarkGrey4')

layout_frame1 = [
    [blank_frame(), blank_frame()],
    [sg.Frame("Frame 3", [[blank_frame()]], pad=(5, 3), expand_x=True, expand_y=True, title_location=sg.TITLE_LOCATION_TOP)],
]

layout_frame2 = [[blank_frame()]]

layout = [
    [sg.Frame("Frame 1", layout_frame1, size=(280, 250)),
     sg.Frame("Frame 2", layout_frame2, size=(200, 250), title_location=sg.TITLE_LOCATION_TOP)],]

window = sg.Window("Title", layout, margins=(2, 2), finalize=True)

while True:

    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break

window.close()

enter image description here

Upvotes: 6

Related Questions