python PySimpleGUIでListboxの文字色や背景色を設定する

pythonで、ライブラリPySimpleGUIを使用して、Listboxの文字色や背景色を設定するサンプルコードを記述してます。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
Listboxの文字色や背景色を設定
Listboxの文字色や背景色は「text_color」と「background_color」で指定することが可能です。
import PySimpleGUI as sg
sg.Listbox( ["one", "two", "three"], text_color='#000', background_color='#37B507')
以下は、Listboxの文字色や背景色を指定したサンプルコードとなります。
import PySimpleGUI as sg
# ウィンドウのテーマ
sg.theme('BlueMono')
# リストボックスのサイズ
width = 50
height = 50
# ウィンドウのレイアウト
layout = [
[sg.Text('リストボックス')],
[sg.Listbox( ["one", "two", "three"], text_color='#fff', background_color='#37B507', size=(width,height)) ]
]
# ウィンドウオブジェクトの作成
window = sg.Window('title', layout, size=(300, 300))
# イベントのループ
while True:
# イベントの読み込み
event, values = window.read()
# ウィンドウの×ボタンクリックで終了
if event == sg.WIN_CLOSED:
break
# ウィンドウ終了処理
window.close()
実行結果

-
前の記事
VSCODE redisに接続して使用する 2022.01.08
-
次の記事
javascript lodashを使ってオブジェクトの値を変更する 2022.01.09
コメントを書く