def s1():
import PySimpleGUI as sg
sg.theme('Dark Green 2')
layout = [ [sg.Text('My Window')],
[sg.Input(key='-IN1-')],
[sg.Input(key='-IN2-')],
[sg.Input('失去焦点事件',key='-IN3-')],
[sg.Input('是否可见', key='-IN4-',visible=False)],
[sg.Button('可见',key='-Btn4-')],
[sg.Button('鼠标左键事件'),
sg.Button('鼠标中间键事件'),
sg.Button('鼠标右键事件'),
sg.Button('双击事件'),
sg.Button('Unbind'),sg.Button('Exit')],
]
window = sg.Window('Window Title', layout, finalize=True)
window.bind("<Button-1>", 'Window Click')
window['鼠标右键事件'].bind("<Button-3>", ' +RIGHT CLICK+')
window['鼠标左键事件'].bind("<Button-1>", ' +LEFT CLICK+')
window['鼠标中间键事件'].bind("<Button-2>", ' +MIDDLE CLICK+')
window['双击事件'].bind("<Double-Button-1>", ' +Double CLICK+')
window['-IN2-'].bind("<FocusIn>", ' +FOCUS+')
window['-IN3-'].bind("<FocusOut>", ' +FOCUSOut+')
window['-IN4-'].bind("<Visibility>", ' +Visibility+')
while True:
event, values = window.read()
print(event)
if event in (sg.WIN_CLOSED, 'Exit'):
break
if event == 'Unbind':
window['Go'].unbind('<Button-3>')
if event == '-Btn4-':
if window['-IN4-'].visible:
window['-IN4-'].update(visible=False)
else:
window['-IN4-'].update(visible=True)
window.close()
s1()