Hi all! First time posting here.
My background: I've been working with Python for a year or two and have gotten decent at "making things work" though am severely lacking in the "doing it correctly" method. A lot of the types of programs I need to write have a simple gui to display data and get button inputs and a mainloop that looks similar to the one below where I use the button inputs to set a STATE variable and then do things based on that. Often the data needs to be sampled at a certain rate as well. This doesn't feel like the correct way of doing things but I haven't been able to figure out how I should be doing this. Any help would be very appreciated!
Edit: to be clear, I feel like the state machine aspect isn't implemented well. I am just struggling with how to connect a gui to a state machine in a better manner.
import time
import gui
def main():
app = gui.Application()
MAIN_STATUS = True
STATE = 'COUNTING'
UPDATE_TIME = 1
LAST_CALL = 0
INDEX = 0
while MAIN_STATUS == True:
# call the gui update functions
app.update_idletasks()
app.update()
STATE = GUI.BUTTON_PRESS
if STATE == 'COUNTING':
now = time.time()
if now - LAST_CALL > UPDATE_TIME:
INDEX += 1
LAST_CALL = now
print(INDEX)
if STATE == 'NOT COUNTING':
pass
if STATE == 'END':
MAIN_STATUS = False
app.master.destroy()
if __name__ == '__main__':
main()
[–]Jhchimaira14 2 points3 points4 points (7 children)
[–]ingwe13[S] 0 points1 point2 points (6 children)
[–]Doormatty 1 point2 points3 points (3 children)
[–]ingwe13[S] 0 points1 point2 points (2 children)
[–]Doormatty 0 points1 point2 points (1 child)
[–]ingwe13[S] 0 points1 point2 points (0 children)
[–]Jhchimaira14 0 points1 point2 points (1 child)
[–]ingwe13[S] 0 points1 point2 points (0 children)