クイズアプリや四選択肢クイズに便利なテンプレート
import PySimpleGUI as sg
# レイアウトの定義
left_layout = [
[sg.Image(key=’-IMAGE-‘, size=(200, 200))]
]
right_layout = [
[sg.Text(‘Text 1:’), sg.InputText()],
[sg.Text(‘Text 2:’), sg.InputText()],
[sg.Text(‘Text 3:’), sg.InputText()]
]
button_frame = [
[sg.Button(‘Button 1’), sg.Button(‘Button 2’), sg.Button(‘Button 3’)],
[sg.Button(‘Button 4’), sg.Button(‘Button 5’), sg.Button(‘Button 6’)]
]
bottom_right_layout = [
[sg.Text(‘Right Bottom Text’)]
]
layout = [
[sg.Frame(‘Left Layout’, left_layout, element_justification=’center’, size=(300, 300)),
sg.Frame(‘Right Layout’, right_layout, element_justification=’center’, size=(300, 300))],
[sg.Column(button_frame, element_justification=’center’, justification=’center’)],
[sg.Column(bottom_right_layout, justification=’right’)]
]
# ウィンドウの作成
window = sg.Window(‘My Window’, layout, finalize=True)
# ウィンドウを表示する
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
# ウィンドウを閉じる
window.close()
こんなwindowが出来ます。
