python PySimpleGUIのProgressBarに枠線をつける

python PySimpleGUIのProgressBarに枠線をつける

pythonで、ライブラリPySimpleGUIを使用して、ProgressBarに枠線をつけるサンプルコードを記述してます。pythonのバージョンは3.8.5を使用してます。

環境

  • OS windows10 pro 64bit
  • python 3.8.5

PySimpleGUIインストール

PySimpleGUIをインストールされていない方は、pipでインストールしておきます。

PySimpleGUI

<出力結果>
Collecting PySimpleGUI
  Downloading PySimpleGUI-4.41.2-py3-none-any.whl (348 kB)
     |████████████████████████████████| 348 kB 1.3 MB/s
Installing collected packages: PySimpleGUI
Successfully installed PySimpleGUI-4.41.2

枠線をつける

枠をつける場合は「relief」に各スタイルを指定することで可能です。

import PySimpleGUI as sg

sg.ProgressBar(100, relief=sg.RELIEF_SOLID, border_width=5 )
sg.ProgressBar(100, relief=sg.RELIEF_RAISED, border_width=5 )
sg.ProgressBar(100, relief=sg.RELIEF_SUNKEN, border_width=5 )
sg.ProgressBar(100, relief=sg.RELIEF_RIDGE, border_width=5 )
sg.ProgressBar(100, relief=sg.RELIEF_GROOVE, border_width=5 )

以下は、ProgressBarの枠線を指定したサンプルコードとなります。

import PySimpleGUI as sg

# ウィンドウのテーマ
sg.theme('LightGrey3')

# ウィンドウのレイアウト
layout=[
            [sg.Slider(range=(0 ,100),orientation='h', size=(25, 15), enable_events=True, key='sld1')],
            [sg.ProgressBar(100,orientation='h', relief=sg.RELIEF_SOLID, border_width=5, key='pbar1', bar_color=('#39B60A','#fff'))],
            [sg.ProgressBar(100,orientation='h', relief=sg.RELIEF_RAISED, border_width=5, key='pbar2', bar_color=('#39B60A','#fff'))],
            [sg.ProgressBar(100,orientation='h', relief=sg.RELIEF_SUNKEN, border_width=5, key='pbar3', bar_color=('#39B60A','#fff'))],
            [sg.ProgressBar(100,orientation='h', relief=sg.RELIEF_RIDGE, border_width=5, key='pbar4', bar_color=('#39B60A','#fff'))],
            [sg.ProgressBar(100,orientation='h', relief=sg.RELIEF_GROOVE, border_width=5, key='pbar5', bar_color=('#39B60A','#fff'))]
        ]

# ウィンドウオブジェクトの作成
window = sg.Window('title', layout, size=(300, 300))

# イベントのループ
while True:
    # イベントの読み込み
    event, values = window.read()
    # ウィンドウの×ボタンクリックで終了
    if event == sg.WIN_CLOSED:
        break
    elif event == 'sld1':
        window['pbar1'].UpdateBar(values['sld1'])
        window['pbar2'].UpdateBar(values['sld1'])
        window['pbar3'].UpdateBar(values['sld1'])
        window['pbar4'].UpdateBar(values['sld1'])
        window['pbar5'].UpdateBar(values['sld1'])
# ウィンドウ終了処理
window.close()

実行結果