【Python】PythonでGUI
2021年3月29日
PythonでもGUIアプリを作れます。その方法がこちら。Qt、tkinterなどが有名ですが、これらのWrapperであるPySimpleGUIもいいかもしれません。
まずは、モジュールをインストールして。
pip3 install pysimplegui
次のようなコードを実行します。
import PySimpleGUI as sg
sg.theme('Black')
layout = [
[sg.Text('Python GUI')],
[sg.Text('Name', size=(10, 1)), sg.InputText()],
[sg.Text('E-mail', size=(15, 1)), sg.InputText('***@*****')],
[sg.Submit(button_text='Submit')]
]
window = sg.Window('Send e-mail', layout)
while True:
event, values = window.read()
if event is None:
break
if event == 'Submit':
show_message = "Your name is:" + values[0] + '\n'
show_message += "Your e-mail is :" + values[1] + '\n'
sg.popup(show_message)
window.close()
実行すると、こんなダイアログが表示されます。

“Submit”ボタンを押すと、もう一つダイアログが出てきます。

お手軽です。
”Tkinterを使うのであればPySimpleGUIを使ってみたらという話”を参考にさせていただきました。