GUI 初歩の中国語(bind使用)

マウスを押下したままで問題が表示され、リリースすると回答・ピンイン・備考が表示される

ボタンのon/offで切り替わる方法は一般的だが、ボタンの押し先を動かすのは面倒なので
press・releaseが上手く動作して嬉しい。 ChatGUIに質問したが、何故か正解を貰えなかった。

# 初歩の中国語(bind)ver2.0.py 1/29/2024

import PySimpleGUI as sg
import random

sg.theme('Kayak')

menu=[
['使い方',['ボタン「次へ」を押下したままにすると、問題が表示されます。 マウスをリリース(離す)すると答え、ピンイン、備考が表示されます', ' ','閉じる']]]

with open("中国語基礎1_29_2024.txt", "r", encoding="utf-8") as f:
    word_list = [line.split('\t') for line in f.readlines()]

number_word = len(word_list)
print(number_word)

layout = [
    [sg.Menu(menu)],
    [sg.Text('Question', size=(5, 1)), sg.InputText("ここに問題が出ます。 ", text_color='red', size=(50, 1), font=('Arial', 14, 'bold' ), key='-question-')],
    [sg.Text('Answer', size=(5, 1)), sg.InputText("ここに回答が出ます ", text_color='blue', size=(50, 1), font=('Arial', 14, 'bold'), key='-meaning-')],
    [sg.Text('Pinyin', size=(5, 1)), sg.InputText("ここにピンイン記号が出ます。 ", text_color='blue', size=(50, 1), font=('Arial', 14, 'bold'), key='-pinyin-')],
    [sg.Text('Reference', size=(7, 1)), sg.Multiline("ここに備考が出ます。 ", size=(50,4), text_color='black', font=('Arial', 14, 'bold'), key='-ref-')],
    [sg.Button('Next', key='-ok-', size=(10, 1)),
     sg.Button('Quit', size=(10, 1))],
    [sg.Text('Tak ver 2.0', justification='right', size=(58, 1), key='version')]
]

# make the window
window = sg.Window('初歩の中国語', layout,element_justification='c', finalize=True)
window["-ok-"].bind("<ButtonRelease>", "-release-", propagate=False)
window["-ok-"].bind("<ButtonPress>", "-press-", propagate=False)

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

    if event  in (None, 'Quit'):
        break

    if event == '-ok--press-':
        new_index = random.randint(0, len(word_list)-1)
        window['-question-']. Update(" "+word_list[new_index][0])
        window['-meaning-']. Update(" ")
        window['-pinyin-'].Update(" ")
        window['-ref-']. Update(" ")
        #window['-ok-'].Update('Show_meaning')
    elif event == '-ok--release-':
        window['-meaning-']. Update(" "+word_list[new_index][1])
        window['-pinyin-'].Update(" "+word_list[new_index][2])
        window['-ref-']. Update(word_list[new_index][3])
        #window['-ok-'].Update('Next')

window.close()