Article 4YF6C Update text in TkInter GUI?

Update text in TkInter GUI?

by
RonHof
from LinuxQuestions.org on (#4YF6C)
I'm trying to read a serial data stream and display it in a tkinter GUI on a Raspberry Pi. The following code seems to work properly.
Code:#!/usr/bin/env python
import time
import serial
import string

ser = serial.Serial (port='/dev/ttyUSB0',
baudrate = 4800,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 1)
while 1:

Str = ser.read_until(b'\r')
print (Str)and produces the followng typical output
Quote:
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 1.36\r'
b' 0.06\r'
b' 0.10\r'
b' 0.15\r'
I would like to display that text in a gui as it updates. The following code produces a window with the first line of text but it doesn't update with each new line of text.
Code:#!/usr/bin/env python3

from tkinter import *
from tkinter import Label
import serial

#root = Tk()

ser = serial.Serial (port='/dev/ttyUSB0',
baudrate = 4800,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 1)

while TRUE:
Str = ser.read_until(b'\r')
#print (Str)

labelfont = ('times', 350, 'bold')
widget = Label(None, text = Str)
widget.config(bg='black', fg='red')
widget.config(font=labelfont)
widget.config(height=3, width=20)
widget.pack(expand=YES, fill=BOTH)

widget.mainloop()What am I missing?
Thankslatest?d=yIl2AUoC8zA latest?i=0-AFz5yI5MQ:MqrVB62Evvk:F7zBnMy latest?i=0-AFz5yI5MQ:MqrVB62Evvk:V_sGLiP latest?d=qj6IDK7rITs latest?i=0-AFz5yI5MQ:MqrVB62Evvk:gIN9vFw0-AFz5yI5MQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments