2019-12-18 21:27:59 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
|
|
|
|
"""
|
|
|
|
Extending PySimpleGUI using the tkinter event bindings
|
|
|
|
|
|
|
|
The idea here is to enable you to receive tkinter "Events" through the normal place you
|
|
|
|
get your events, the window.read() call.
|
|
|
|
|
|
|
|
Both elements and windows have a bind method.
|
|
|
|
window.bind(tkinter_event_string, key) or element.bind(tkinter_event_string, key_modifier)
|
|
|
|
First parameter is the tkinter event string. These are things like <FocusIn> <Button-1> <Button-3> <Enter>
|
|
|
|
Second parameter for windows is an entire key, for elements is something added onto a key. This key or modified key is what is returned when you read the window.
|
|
|
|
If the key modifier is text and the key is text, then the key returned from the read will be the 2 concatenated together. Otherwise your event will be a tuple containing the key_modifier value you pass in and the key belonging to the element the event happened to.
|
2021-03-12 18:08:20 +00:00
|
|
|
|
|
|
|
Copyright 2021 PySimpleGUI
|
2019-12-18 21:27:59 +00:00
|
|
|
"""
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Dark Blue 3')
|
2019-12-18 21:27:59 +00:00
|
|
|
|
2020-09-20 19:54:37 +00:00
|
|
|
def main():
|
|
|
|
layout = [ [sg.Text('Move mouse over me', key='-TEXT-')],
|
|
|
|
[sg.In(key='-IN-')],
|
2021-03-12 18:08:20 +00:00
|
|
|
[sg.Button('Right Click Me', key='-BUTTON-'), sg.Button('Right Click Me2', key=(2,3)),sg.Button('Exit'),]]
|
2019-12-18 21:27:59 +00:00
|
|
|
|
2020-09-20 19:54:37 +00:00
|
|
|
window = sg.Window('Window Title', layout, finalize=True)
|
2019-12-18 21:27:59 +00:00
|
|
|
|
2020-09-20 19:54:37 +00:00
|
|
|
window.bind('<FocusOut>', '+FOCUS OUT+')
|
2019-12-18 21:27:59 +00:00
|
|
|
|
2020-09-20 19:54:37 +00:00
|
|
|
window['-BUTTON-'].bind('<Button-3>', '+RIGHT CLICK+')
|
|
|
|
window[(2,3)].bind('<Button-3>', '+RIGHT CLICK+')
|
|
|
|
window['-TEXT-'].bind('<Enter>', '+MOUSE OVER+')
|
|
|
|
window['-TEXT-'].bind('<Leave>', '+MOUSE AWAY+')
|
|
|
|
window['-IN-'].bind('<FocusIn>', '+INPUT FOCUS+')
|
2021-03-12 18:08:20 +00:00
|
|
|
window.bind('<Enter>', '* WINDOW ENTER *')
|
2020-09-20 19:54:37 +00:00
|
|
|
while True: # Event Loop
|
|
|
|
event, values = window.read()
|
|
|
|
print(event, values)
|
|
|
|
if event in (sg.WIN_CLOSED, 'Exit'):
|
|
|
|
break
|
|
|
|
window.close()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-03-12 18:08:20 +00:00
|
|
|
main()
|