python PySimpleGUIのOptionMenuの位置を設定する

python PySimpleGUIのOptionMenuの位置を設定する

pythonで、ライブラリPySimpleGUIを使用して、OptionMenuの位置を設定するサンプルコードを記述してます。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.OptionMenu([1,'mebee','site'], pad=((左からの位置,右からの位置),(上からの位置,下からの位置)))

以下は、OptionMenuの位置を指定したサンプルコードとなります。

import PySimpleGUI as sg

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

# 位置
left=100
right=10
top=20
bottom=20

# ウィンドウのレイアウト
layout=[
        [sg.OptionMenu([1,'mebee','site'], pad=((left,right),(top,bottom)))]
    ]

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

# イベントのループ
while True:
    # イベントの読み込み
    event, values = window.read()
    # ウィンドウの×ボタンクリックで終了
    if event == sg.WIN_CLOSED:
        break
# ウィンドウ終了処理
window.close()

実行結果