From 9d4d6d42cc84615efb18f0ecd7bc38b184eeb401 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Fri, 12 Mar 2021 13:07:57 -0500 Subject: [PATCH] New demo to show how to use 1 line of code to add a hotkey to your program --- DemoPrograms/Demo_Hotkey.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 DemoPrograms/Demo_Hotkey.py diff --git a/DemoPrograms/Demo_Hotkey.py b/DemoPrograms/Demo_Hotkey.py new file mode 100644 index 00000000..6dafcea1 --- /dev/null +++ b/DemoPrograms/Demo_Hotkey.py @@ -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('', '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('', 'Go') + +while True: # Event Loop + event, values = window.read() + print(event, values) + if event in (None, 'Exit'): + break + +window.close() \ No newline at end of file