New demo to show how to use 1 line of code to add a hotkey to your program
This commit is contained in:
parent
501b175c34
commit
9d4d6d42cc
|
@ -0,0 +1,31 @@
|
||||||
|
import PySimpleGUI as sg
|
||||||
|
"""
|
||||||
|
Demo Hotkey
|
||||||
|
|
||||||
|
Want a keyboard hotkey to cause your program to take some action
|
||||||
|
that's identical to a button being clicked?
|
||||||
|
|
||||||
|
Well... that's 1 line of code that's needed.
|
||||||
|
|
||||||
|
This line binds the F10 keybaord key to the window. It produces a "Go" event:
|
||||||
|
window.bind('<F10>', 'Go')
|
||||||
|
|
||||||
|
Copyright 2021 PySimpleGUI
|
||||||
|
"""
|
||||||
|
|
||||||
|
layout = [ [sg.Text('Press F10 to get same result as clicking "Go" button')],
|
||||||
|
[sg.Input(key='-IN-')],
|
||||||
|
[sg.Output(size=(30,8))],
|
||||||
|
[sg.Button('Go'), sg.Button('Exit')] ]
|
||||||
|
|
||||||
|
window = sg.Window('Window Title', layout, finalize=True)
|
||||||
|
|
||||||
|
window.bind('<F10>', 'Go')
|
||||||
|
|
||||||
|
while True: # Event Loop
|
||||||
|
event, values = window.read()
|
||||||
|
print(event, values)
|
||||||
|
if event in (None, 'Exit'):
|
||||||
|
break
|
||||||
|
|
||||||
|
window.close()
|
Loading…
Reference in New Issue