Python Forum

Full Version: Help with infinite loops using GUI?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Raspberry Pi 3 B+
Python 3.5
GuiZero

I have created a basic program in Python v3 using the Command Line that would read a temperature sensor, print the results to the screen, wait 5 seconds and do it again. This was more of a test of the sensor than anything. Works great using a while True: loop.

Now I'm moving into Python 3.5 Idle w/GuiZero and have created a simple App layout. I have a textbox on form I wish to display this same temperature information. It works great if I click a button that is linked to the code for updating the field, but how do I create a loop so this will happen automatically every 5 seconds?

It seems that if I put any kind of while True: loop in the code it keeps the GUI from loading... I know I must be doing something wrong... HELP!

Thanks!
  • Show code
  • Inform as to which GUI you are using
  • Indicate suspect lines.
  • Show error traceback verbatim (if any)
  • Tell us Python version
I'm sorry guys.. I just stumbled upon my answer!

app.repeat(milliseconds, function)

#App Stuff
app = App("thermoThis GUI")

button1 = PushButton(app, command=testButton, text="Relay Heat")
button2 = PushButton(app, command=getTempSensorValues, text="Get Temps")

app.repeat(5000, getTempSensorValues)

app.display()