python - 如何在从 PySimpleGUI 库创建的窗口对象中制作可调整大小的元素?

标签 python user-interface responsive desktop-application pysimplegui

我已经创建了一个 Python 代码的 GUI。我在窗口中创建了一些元素。我希望元素能够响应窗口大小。我在窗口对象中添加了一个 resizable=true 属性,但它只会使应用程序窗口响应而不是窗口中包含的元素。

申请代码

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)

原始尺寸的图片 This is the window that appears when we compile and run the code

现在,如果我单击最大化按钮,窗口将显示为

最佳答案

设置元素的选项 expand_x=True 或/和 expand_y=True,如果需要,也可能为其容器设置相同的设置。

  • expand_x:如果为 True,该列将自动在 X 方向扩展以填充可用空间
  • expand_y:如果为 True,该列将自动在 Y 方向扩展以填充可用空间
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)

关于python - 如何在从 PySimpleGUI 库创建的窗口对象中制作可调整大小的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71829302/

相关文章:

python - python Z3 API 的性能

user-interface - 哪个是黑莓应用程序开发的更好工具?

html - 将 div 定位在 (align-item) 拉伸(stretch)的 div 下方

javascript - 在响应式图片上显示/隐藏链接

html - 制作响应式多个div

python - 将元组的元组转换为列表并删除多余的括号

python - 如何将单引号括在 python 字典周围以使其成为 JSON?

python - “Pip install”导致“error: command ' gcc ' failed with exit status 1”

c++ - 如何设置位图作为子窗口的背景(WIN32)

wpf - 您如何解决 WPF UI 问题?