Initial checkin of Keyboard Demos

This commit is contained in:
MikeTheWatchGuy 2018-08-20 19:00:02 -04:00
parent 88bdf72d8a
commit e0deebea9e
2 changed files with 49 additions and 0 deletions

26
Demo_Keyboard.py Normal file
View File

@ -0,0 +1,26 @@
import sys
import PySimpleGUI as sg
# Recipe for getting keys, one at a time as they are released
# If want to use the space bar, then be sure and disable the "default focus"
with sg.FlexForm('Realtime Keyboard Test', return_keyboard_events=True, use_default_focus=False) as form:
text_elem = sg.Text('', size=(12,1))
layout = [[sg.Text('Press a key')],
[text_elem],
[sg.SimpleButton('OK')]]
form.Layout(layout)
# ---===--- Loop taking in user input --- #
while True:
button, value = form.Read()
if button == 'OK':
print(button, 'exiting')
break
if button is not None:
text_elem.Update(button)
elif value is None:
break

23
Demo_Keyboard_Realtime.py Normal file
View File

@ -0,0 +1,23 @@
import PySimpleGUI as sg
# Recipe for getting a continuous stream of keys when using a non-blocking form
# If want to use the space bar, then be sure and disable the "default focus"
with sg.FlexForm('Realtime Keyboard Test', return_keyboard_events=True, use_default_focus=False) as form:
layout = [[sg.Text('Hold down a key')],
[sg.SimpleButton('OK')]]
form.Layout(layout)
# ---===--- Loop taking in user input --- #
while True:
button, value = form.ReadNonBlocking()
if button == 'OK':
print(button, value, 'exiting')
break
if button is not None:
print(button)
elif value is None:
break