-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathDemo_Keyboard.py
More file actions
34 lines (25 loc) · 889 Bytes
/
Demo_Keyboard.py
File metadata and controls
34 lines (25 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
import sys
import PySimpleGUI as sg
"""
Copyright 2018-2026 PySimpleGUI. All rights reserved.
"""
# 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"
layout = [[sg.Text("Press a key or scroll mouse")],
[sg.Text("", size=(18, 1), key='text')],
[sg.Button("OK", key='OK')]]
window = sg.Window("Keyboard Test", layout,
return_keyboard_events=True, use_default_focus=False)
# ---===--- Loop taking in user input --- #
while True:
event, values = window.read()
text_elem = window['text']
if event in ("OK", None):
print(event, "exiting")
break
if len(event) == 1:
text_elem.update(value='%s - %s' % (event, ord(event)))
if event is not None:
text_elem.update(event)
window.close()