@GOU_KUN

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

PythonのPySimpleGUIのリストについて

解決したいこと

PythonのPySimpleGUIを使ってGUIアプリケーションを作っています。
しかし、リスト上にあるやつの作り方が分かりません。
(↓黄色で囲った部分ような奴のことです。)
スクリーンショット 2021-02-08 200450.png

理想

理想.png

現実

ソースコード

見た目の部分だけ書いてみたらこうなりました。

import PySimpleGUI as sg
listEdit = sg.Frame("",[[sg.Button("新規")],
                        [sg.Button("編集")],
                        [sg.Button("削除")],
                        ])

bar = ["No  Name                                                            Date"]

lists = sg.Frame("一覧",[[sg.Listbox(bar,[], size=(50, 15),enable_events=True, key='LIST'),listEdit],])

Layout = [  [lists],
            [sg.Button("OK"), sg.Button("Cancel")] ]
Window = sg.Window("設定", Layout,icon='ico.ico', no_titlebar=True, alpha_channel=0.95,grab_anywhere=True,return_keyboard_events=True)

while True:
    event,values = Window.read()
    if event == sg.WIN_CLOSED or event == 'Cancel' or event == 'Escape:27':
        break
Window.close()

結果...

現実.png
無理やりスペースで間をあけてリストの初期値としています。
しかし、これでは縦線がなく、見た目がとても悪いです。しかも、右側のボタンの周りに余計な線が入っていたり、間が空いていなかったりして、ダサさに磨きがかかっています。

どなたかわかる方、解決方法を教えてください。

0 likes

2Answer

取り敢えず枠線が欲しいのであれば、こういうやり方はいかがでしょうか?

code
import PySimpleGUI as sg

sg.theme('Dark Brown 1')
headings = ['HEADER 1', 'HEADER 2', 'HEADER 3','HEADER 4']
header =  [[sg.Text('  ')] + [sg.Text(h, size=(14,1)) for h in headings]]
rows = [[sg.Text(size=(15,1), pad=(1,1), background_color='LightYellow3') for col in range(4)] for row in range(10)]
layout = header + rows
window = sg.Window('Table Simulation', layout, font='Courier 12')
event, values = window.read()

スクリーンショット 2021-02-09 010508.png

  • 背景色を指定したTextを配置した表になっています。
    • 元にしたのは、Inputを配置した表でした。
    • pad()で周囲の隙間が調整できるみたいですね。
  • PySimpleGUI User's Manual」をざっと眺めてみましたが、なにせ "PySimpleGUI" ですので、デザインはある程度妥協するしかないのかなと思います。
0Like

すみません、知識不足でした。
今調べて分かったことなのですが、作ろうとしていたのは「テーブル」というものだそうです。
自分で調べて作ってみます。
初歩的な質問すみませんでした。

0Like

Your answer might help someone💌