I am working on a program in Python with guizero (running on a Raspberry Pi) with witch users can select drinks and identify with an RFID Chip. The transaction is then stored in a mariadb on a remote device.
The idea is that users selects a drink, then the screen changes for 10 Seconds to a promt where he is asked to authenticate with his RFID chip . If he does not, the software should return to the main screen.
So far, everything works well but I am having trouble with the GUI. Since the 10 Second-Scan-Period is a while-Loop, it freezes the whole gui and does not show the promt, and leaving the user clueless of what he has to do.
What I've tried:
- I used a Thread-Object to call the scan function, but that resulted in the promt disappearing very fast.
- I tried callbacks but that meant to freeze my gui anyway
- I tried the repeat-method for the App-Object and removing the while-loop, but that would mean that the system is scanning non-stop, which is not intended.
Here's a little example-code which describes my program in a very simple way:
from guizero import App, Text, PushButton
explanation = "To scan your chip, please click on the button."
def scan():
text.value = "Scanning...."
#set the endtime to ten seconds from now
endtime = time.time() + 10
#repeat for ten seconds
while time.time() < endtime:
print("Scanning for RFID")
print("End of scan")
text.value = explanation
app = App("Funny Title Here")
#initial welcome text
text = Text(app,text=explanation)
#if button is clicked, change the text and scan for ten seconds
button = PushButton(app, command=scan, text="Scan")
app.display()
I know that one of the methods I tried is the right one, but I seem to lack the needed logic. So my question is: How can I achieve, that the gui updates after the user pushed a button, starts to scan for RFID cards, and after 10 seconds stops and returns to the original view?
Thanks