UHpi
UHpi

Reputation: 113

How to make resizable elements in a window object created from PySimpleGUI library?

I have created a GUI of a python code. I have created some elements in the window. I want the elements to be responsive to the window size. I have added a resizable=true property in the window object but it only makes the application window responsive not the elements contained within the window.

Code of Application

sg.theme('DefaultNoMoreNagging')
    video_frame_column = [
        [sg.Text("Scanner", justification="center")],
        [sg.Image(filename="", key="-IMAGE-")]
    ]
    functional_column = [
        [sg.Text("Log Settings", justification="center")],
        [   
            sg.Text("Scanned ID:", justification="center"), 
            sg.Text(size=(30, 1), key="-TOUT-", justification="center", background_color="white")
        ],
        [sg.Button("Enter")],
        [sg.Button("Exit")],
        [sg.Button("Display Log")]
    ]
    layout=[
            [
                sg.Column(video_frame_column),
                sg.VSeperator(),
                sg.Column(functional_column, element_justification='c')
            ]
        ]
    window = sg.Window("Entry/Exit Log Management System", layout, location=(300, 150), resizable=True, finalize=True)

Image of the original size it has This is the window that appears when we compile and run the code

Now if I click the maximize button the window appears as

Upvotes: 3

Views: 3817

Answers (1)

Jason Yang
Jason Yang

Reputation: 13061

Set options expand_x=True or/and expand_y=True of element, maybe also same settings for its container if required.

  • expand_x: If True the column will automatically expand in the X direction to fill available space
  • expand_y: If True the column will automatically expand in the Y direction to fill available space
import PySimpleGUI as sg

sg.theme('DefaultNoMoreNagging')

video_frame_column = [
    [sg.Text("Scanner", justification="center")],
    [sg.Image(filename='d:/images.png', background_color='green', expand_x=True, expand_y=True, key="-IMAGE-")]
]
functional_column = [
    [sg.Text("Log Settings", justification="center")],
    [
        sg.Text("Scanned ID:", justification="center"),
        sg.Text(size=(30, 1), key="-TOUT-", justification="center", background_color="white")
    ],
    [sg.Button("Enter")],
    [sg.Button("Exit")],
    [sg.Button("Display Log")]
]
layout=[
        [
            sg.Column(video_frame_column, expand_x=True, expand_y=True),
            sg.VSeperator(),
            sg.Column(functional_column, element_justification='c')
        ]
    ]
window = sg.Window("Entry/Exit Log Management System", layout, location=(300, 150), resizable=True, finalize=True)
window.read(close=True)

Upvotes: 2

Related Questions