Before I begin let me just say that I only started learning Python and coding a couple days ago so I'm aware I may have missed something in the learning process.
The intended function of this program is to allow someone with limited communication to be able to speak or have at least basic communication. What the program does is begin cycling between options automatically with a set time interval in between. This allows an option to be displayed long enough for the person to click a single button to select that option. That option would then be displayed. The whole premise is communication with just one button click or other single sensory input. This sample from the much larger program just asks the user "Yes?" or "No?" but the rest of the program functions using the same format. Currently, "No" is going to be selected for testing purposes because it's hardcoded in until I add the GPIO functionality.
The program does exactly what I need it to but now I'd like to make the text that is normally returned using print() in the IDE to be displayed on a 7" screen to make it more user friendly. Therefore, I need to make a GUI. All I need it to do is display the same text. However, from what I've been reading pretty much none of my program works with a GUI.
-Can't use while
-Can't use sleep.time
Which are the two most important functions of the program... I've tried to find alternatives that will work with something basic like tkinter or Guizero but nothing seems like a straightforward solution. I've looked at threading, and the after/repeat functions of Guizero but so far haven't gotten them to work.
What I need to solve to fix the issues:
-A different way to handle the automatic option cycling time interval
-A way to replace the while loop
Any help I can get on this would be very appreciated. In the meantime I'll keep grinding for a solution. Thanks!
Code: Select all
import time def yesnomode(): count = 0 switch_state = 15 # Variable that holds live value switch_thresh = 10 # Variable to tune the threshold button_state = 0 # Variable that holds live value button_thresh = 10 # Variable to tune the threshold rate = 1.5 # Rate that the options will cycle print("Beginning Yes or No Mode") while switch_state >= switch_thresh: # if switch reaches threshold then begin option cycling count = count + 1 time.sleep(rate) # This is the rate that the options will cycle if count == 1: print("Yes?") if button_state >= button_thresh: print("Yes Selected") time.sleep(rate) if count == 2: print("No?") button_state = 10 if button_state >= button_thresh: time.sleep(rate) print("No Selected") button_state = 0 if count == 3: count = 0 yesnomode()