I was looking at example 3.py and see a number of problems with using this as an example.
This is a corrected version that I would recommend.
import PySimpleGUI as sg
sg.theme('Dark Green 6')
layout = [[sg.Text('Please click the button', key='-TEXT-')],
[sg.Button('実行ボタン')]]
# ウィンサイズはsizeに(縦の大きさ,横の大きさ)で記載
window = sg.Window('show input text', layout)
# イベントループ
while True:
event, values = window.read()
if event is None:
break
if event == '実行ボタン':
update_text = "Button clicked."
# 表示内容を更新する際はウィジェットに指定されたkeyの値に.update("文字列")を入れることで可能
window['-TEXT-'].update(update_text)
window.close()
I'll address each of them. Don't use the shortcut Submit
and change the text. If you're making a button with custom text, use Button
. The point is to teach people how to make a Button rather than how to modify a shortcut like Submit
. Submit
is nothing more than Button("Submit")
|
[sg.Submit(button_text='実行ボタン')]] |
"Chained" calls are no longer recommended and have been removed from all documentation and demo programs. Specification of layouts is now done as the second parameter to the Window
call, title
is always the first.
To keep the code looking and feeling simple, put the parameters in their correct locations and drop the use of keyword arguments.
I'm confused as to why a size
is being specified in this window. Unlike tkinter, Qt, etc, PySimpleGUI sizes the window for you. You do not need to manually specify a size. Keep the program examples as simple as possible. If you are intentionally wanting to show the use of the size parameter, then come up with an example where it's needed and explain why.
|
window = sg.Window(title='show input text', size=(200, 100)).Layout(layout) |
I like the other changes you've made, in particular the use of window[key]
One way to explain this expression window[key]
is that it look just like a dictionary lookup looks. When you find something in a dictionary you specify the key inside of [ ]. Here the "Window" is the dictionary and the element's key is the key. You can think of the Window as being a dictionary of elements and the keys are how they are found. This is how I would explain it to an audience.