I am new to python and tkinter... I am using Tkinter to display a gauge and receive the info through serial com. I have my GUI ready and now need to read the serial values.
The problem I am facing is that I am not being able to read continuously the serial COM.
I came across self.after, but it still does not work. Basically it does not display any value on the console. Any idea what might be wrong?
This is the main code. I have another file meter.py that has the gauge design
import tkinter as tk
import meter as m
import serial
class Mainframe(tk.Frame):
def __init__(self,master,*args,**kwargs):
super(Mainframe,self).__init__(master,*args,**kwargs)
self.meter = m.Meter(self,height = 400,width = 400)
self.meter.setrange(20,90)
self.meter.pack()
tk.Scale(self,width = 15 ,from_ = 20, to = 90
,orient = tk.HORIZONTAL
,command = self.setmeter).pack()
tk.Button(self,text = 'Quit',width = 15,command = master.destroy).pack()
tk.Button(self,text = 'Zoom',width = 15).pack()
def setmeter(self,value):
value = int(value)
self.meter.set(value)
class App(tk.Tk):
def __init__(self):
super(App,self).__init__()
self.title('Try Meter')
Mainframe(self).pack()
def serie():
ser = serial.Serial('COM2', 2400, timeout=1)
line = ser.readline() # read a '\n' terminated line
print (line)
self.after(100,serie)
App().mainloop()