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
位置を設定
位置の設定は「pad」で指定することが可能です。
import PySimpleGUI as sg
sg.ProgressBar(100, pad=((左からの位置,右からの位置),(上からの位置,下からの位置)))
以下は、Sliderの位置を指定したサンプルコードとなります。
import PySimpleGUI as sg
# ウィンドウのテーマ
sg.theme('LightGrey3')
# 位置
left=100
right=10
top=20
bottom=20
# ウィンドウのレイアウト
layout=[
[sg.Slider(range=(0 ,100),orientation='h', size=(25, 15), enable_events=True, key='sld1')],
[sg.ProgressBar(100,orientation='h', pad=((left,right),(top,bottom)), size=(25,15), key='pbar1', bar_color=('#39B60A','#fff'))],
[sg.ProgressBar(100,orientation='h', pad=((left,right),(top,bottom)), size=(25,15), key='pbar2', 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.close()
実行結果

-
前の記事
React.js ライブラリ「use-timer」を使ってタイマーを実装する 2022.02.14
-
次の記事
mongoDB コレクション(テーブル)を一覧で取得する 2022.02.14
コメントを書く