英単語アプリを作る

こんなアプリを作ります。

#GUIアプリとしては最もシンプルなものを作ります。
#codeは次のようになります。

#英単語(fileはcode内).py  9/30/2022

import PySimpleGUI as sg
import random

global word_list : 変数word_listをwhile True以下で使えるようにglobal変数とします。

word_list = [['volition', '決断力'],
                 ['waft', '漂わせる'],
                 ['sundry', '小間物'],
                 ['bower', '東屋'],
                 ['reprieve', '暗記する'],
                 ['rabiform', '狂犬病'],
                 ['evict', '立ち退かせる'],
                 ['rife', '多量の、蔓延って'],
                 ['dicey', '不確かな'],
                 ['enervate', '弱める'],
                 ]

index = random.randint(0,9) # start時に必要

# window's layout
layout = [
    [sg.Text('Question'), sg.InputText(" "+ word_list[index][0], key='-question-')],
    [sg.Text('Meaning'), sg.InputText(" " + word_list[index][1], key='-meaning-')],
    [sg.Button('Next' ,key='-next-')]]

#make the window
window = sg.Window('English', layout)

while True:
    event, values = window.read()

    # end of  application by X button
    if event is None:
        break
   
    if event == '-next-':
        index = random.randint(0,9)
        window['-question-']. Update(" "+word_list[index][0])
       window['-meaning-']. Update(" "+word_list[index][1])   

window.close()

###コメント

*これで見出しのようなGUIができます。
*window['-***-']. Update(" "+word_list[index][0]):
 window['-***-']の文字列を書き換える常套句です。
*key='-question-':-***-と書くとkeyであることが明白なのでそうしているのかな~。