Python Forum
[Tkinter] Write information onto a frame?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Write information onto a frame?
#1
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?
Reply
#2
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/
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 8,938 Sep-30-2019, 07:30 AM
Last Post: Maksim
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 10,991 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,367 Jan-29-2018, 10:44 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020