如何在 PySimpleGUI 中创建 4 列布局?

问题描述 投票:0回答:1

我需要生成一个包含 4 列的表单部分。由于 sg.Table 元素不接受其他元素作为内容,我不确定如何实现并排布局。我已经使用 PySimpleGUI 一段时间了,我真的很喜欢它。研究文档并尝试示例,但这个问题让我很困惑。我尝试了嵌套的 sg.Col 元素,但无法获得这种效果。

使用表格的要点是当复选框标签长度变化时保持列对齐。不需要标题,第一列只是一个多行 sg.Text 标签,用于其他列中的复选框。理想情况下,第一列应垂直居中对齐。

复选框列表将根据 json 配置文件生成。

                    [] bitchute1       [] vimeo7          [] youtube13
 Platforms:         [] bitchute.2      [] vimeo8hhhhhhh   [] youtube14 some size
                    [] bitchute...3    [] vimeo9jjj       [] youtube15
(select all         [] bitchute..4     [] vimeo10uiuyu    [] youtube16 whatever        
 that apply)        [] bitchute...5    [] vimeo11         [] youtube17            
                    [] bitchute6khjhj  [] vimeo12         [] youtube18

在所有试验中,我无法修改示例以保持可变长度内容与列对齐,例如示例,它使用固定宽度的列数据。

python-3.x layout multiple-columns pysimplegui
1个回答
2
投票

Just put 4 columns in the same row with different elements,像

Text
Checkbox
元素。

import PySimpleGUI as sg

checks = [
    ["bitchute", "bitchute.2", "bitchute...3", "bitchute..4", "bitchute...5", "bitchute6khjhj"],
    ["vimeo7", "vimeo8hhhhhhh", "vimeo9jjj", "vimeo10uiuyu", "vimeo11", "vimeo12"],
    ["youtube13", "youtube14 some size","youtube15", "youtube16 whatever", "youtube17", "youtube18"],
]
column = [
    [[sg.Text('Platforms:\n\n(select all\nthat apply)')]]] + [
    [[sg.Checkbox(text, pad=(5, 0), key=('Check', j, i))] for i, text in enumerate(check)] for j, check in enumerate(checks)
]

layout = [[sg.Column(column[i]) for i in range(4)]]
sg.Window('Title', layout).read(close=True)

© www.soinside.com 2019 - 2024. All rights reserved.