Python Forum

Full Version: Write information onto a frame?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am new to GUI on the pi but have used python 3 to sample a temperature probe.
I simply want to open a GUI frame and update it every time there is a new temperature measurement. 
So using this simulation test programme how do i get it to display temperature in the GUI frame every 0.5 seconds.
I don’t want to have a button to press just update the frame with the new value.



import time
for temperature in range(5)
     print(temperature)
     time.sleep(0.5)
This test programme will write temperature to the console output but I want it to write to a GUI frame so I can add additional functionality later.
Any help on tkinter how to achieve this?
You need to learn at least the basics of tkinter.
There are a couple of good tutorials
see:
http://www.python-course.eu/python_tkinter.php
or
http://zetcode.com/gui/tkinter/
Thanks for the link to the tutorials. The second one didn't answer the question but the first one did.
It is the method ".after" that I was after! I can now answer my own question
import tkinter as tk

temperature = 0

def counter_label(label):
  def count():
    global temperature
    temperature += 1
    label.config(text="Temperature="+str(temperature))
    count
    label.after(1000, count)
  count()

 
 
root = tk.Tk()
root.title("Temperature")
label = tk.Label(root, fg="green")
label.pack()
counter_label(label)
button = tk.Button(root, text='Stop', width=25, command=root.destroy)
button.pack()
root.mainloop()