[Tkinter] Write information onto a frame? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Write information onto a frame? (/thread-1255.html) |
Write information onto a frame? - auditdata - Dec-18-2016 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? RE: Write information onto a frame? - Larz60+ - Dec-18-2016 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/ RE: Write information onto a frame? - auditdata - Dec-20-2016 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() |