Fischer
Fischer

Reputation: 1

How to put two Frames next to each other without a gap using pySimpleGUI

I am about to program a registration tool for colleagues where they should be able to register for different days in a week for different times (similar to a Doodle). In order to keep things simple I try to have an organised GUI using pySimpleGUI. I want put all time slots of the same day into a Frame and all days of the same week next to each other in order to have for each week one frame with a line between each day. The Frame layout should look somehow like below

The Frames here are not separated but right next to each other without a gap

What I tried so far is the following:

layout = [[sg.Text('Testing two Frames next to each other')],
            [sg.Frame(layout=[[sg.Text('Day 1')],
                                [sg.Checkbox('Time 1')],
                                [sg.Checkbox('Time 2')]], title = 'Week 1'),
            sg.Frame(layout=[[sg.Text('Day 2')],
                            [sg.Checkbox('Time 1')],
                            [sg.Checkbox('Time 2')]],title='')],
            [sg.Submit(),sg.Cancel()]]

window = sg.Window('Testing Window',layout)
event, values = window.read()
window.close()

The Output is the following.

I would like to have the Frames without a gap in between them and the text on the same height

My problem is that the frames do have a gap in between and the text is not on the same height. Is there maybe some other thing as sg.Frame() to use?

Thanks for your help

Upvotes: 0

Views: 1915

Answers (2)

days = ['Monday', 'Tuesday', 'Wednesday']
row = [sg.Column([[sg.Text(days[0])], [sg.Checkbox('Time 1')], [sg.Checkbox('Time 2')]])]
for day in days[1:]:
    row += [sg.VerticalSeparator(pad=(0, 0)),
            sg.Column([[sg.Text(day)], [sg.Checkbox('Time 1')], [sg.Checkbox('Time 2')]])]
layout = [[sg.Text('Testing two Frames next to each other')],
          [sg.Frame(layout=[row],
                    title='Week 1')],
          [sg.Submit(), sg.Cancel()]]

Upvotes: 0

Jason Yang
Jason Yang

Reputation: 13057

I don't have easy method for it at this moment, just by using option pad of elements.

enter image description here

import PySimpleGUI as sg

sg.theme("DarkBlue")
sg.set_options(font=('Courier New', 12))

frame_1 = [[sg.Text('Day 1')], [sg.Checkbox('Time 1')], [sg.Checkbox('Time 2')],]
frame_2 = [[sg.Text('Day 2', pad=(3, (12, 3)))], [sg.Checkbox('Time 1')], [sg.Checkbox('Time 2')],]

layout = [
    [sg.Frame('Week 1', frame_1, pad=(0, 5)),
     sg.Frame('', frame_2, pad=(0, (14, 5)), key='Hide')],
    [sg.Submit(),sg.Cancel()],
]

window = sg.Window('Testing Window', layout, finalize=True)
while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
    print(event, values)

window.close()

Upvotes: 1

Related Questions