Demo of Realtime Buttons

Remote control demo using Realtime Buttons
This commit is contained in:
MikeTheWatchGuy 2018-07-31 00:01:07 -04:00
parent e4a9f80489
commit bf0c09ac05
1 changed files with 48 additions and 0 deletions

View File

@ -42,6 +42,53 @@ def StatusOutputExample():
form.CloseNonBlockingForm()
def RemoteControlExample():
# Make a form, but don't use context manager
form = sg.FlexForm('Running Timer', auto_size_text=True)
# Create a text element that will be updated with status information on the GUI itself
output_element = sg.Text('', size=(8, 2), font=('Helvetica', 20), justification='center')
form_rows = [[sg.Text('Robotics Remote Control')],
[output_element],
[sg.T(' '*10), sg.RealtimeButton('Forward')],
[ sg.RealtimeButton('Left'), sg.T(' '*15), sg.RealtimeButton('Right')],
[sg.T(' '*10), sg.RealtimeButton('Reverse')],
[sg.T('')],
[sg.Quit()]
]
form.LayoutAndRead(form_rows, non_blocking=True)
#
# Some place later in your code...
# You need to perform a ReadNonBlocking on your form every now and then or
# else it won't refresh.
#
# your program's main loop
i=0
while (True):
# This is the code that reads and updates your window
output_element.Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
button, values = form.ReadNonBlocking()
if button is not None:
print(button)
if button == 'Quit' or values is None:
break
if button == 'LED On':
print('Turning on the LED')
elif button == 'LED Off':
print('Turning off the LED')
i += 1
# Your code begins here
time.sleep(.01)
# Broke out of main loop. Close the window.
form.CloseNonBlockingForm()
# This design pattern follows the uses a context manager to better control the resources
# It may not be realistic to use a context manager within an embedded (Pi) environment
@ -65,6 +112,7 @@ def StatusOutputExample_context_manager():
form.CloseNonBlockingForm()
def main():
RemoteControlExample()
StatusOutputExample()
sg.MsgBox('End of non-blocking demonstration')
# StatusOutputExample_context_manager()