MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Focus_Navigation_Using_Arrow_Keys.py:27–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25
26
27def main():
28 layout = [ [sg.Text('My Window')],
29 [sg.Input(key='-IN-')],
30 [sg.Input(key='-IN2-')],
31 [sg.Input(key='-IN3-')],
32 [sg.Input(key='-IN4-')],
33 [sg.Input(key='-IN5-')],
34 [sg.Input(key='-IN6-')],
35 [sg.Input(key='-IN7-')],
36 [sg.Button('Go'), sg.Button('Exit')]]
37
38 window = sg.Window('Window Title', layout, finalize=True)
39
40 # Bind the Left, Right and Down arrow keys to events
41 window.bind('<Right>', '-NEXT-')
42 window.bind('<Left>', '-PREV-')
43 window.bind('<Down>', 'Exit')
44
45 while True: # Event Loop
46 event, values = window.read()
47 print(event, values)
48 if event == sg.WIN_CLOSED or event == 'Exit':
49 break
50 # Right arrow pressed, so move to the next element that should get focus
51 if event == '-NEXT-':
52 next_element = window.find_element_with_focus().get_next_focus()
53 next_element.set_focus()
54
55 # Left arrow pressed, so move to the previous element that should get focus
56 if event == '-PREV-':
57 prev_element = window.find_element_with_focus().get_previous_focus()
58 prev_element.set_focus()
59 window.close()
60
61if __name__ == '__main__':
62 main()

Calls 7

bindMethod · 0.95
readMethod · 0.95
closeMethod · 0.95
get_next_focusMethod · 0.80
set_focusMethod · 0.80
get_previous_focusMethod · 0.80

Tested by

no test coverage detected