def leertemp():
hora=""
ventanaLectura=Toplevel(root)
ventanaLectura.geometry("630x400")
campos=Frame(ventanaLectura)
campos.pack()
R= Frame(campos, width=500, height=350, bd=8, relief="raise")
R.pack(side=RIGHT)
scrollbary = Scrollbar(R, orient=VERTICAL)
scrollbarx = Scrollbar(R, orient=HORIZONTAL)
tree = ttk.Treeview(R, columns=( "hora","temperatura"), selectmode="extended", height=500, yscrollcommand=scrollbary.set, xscrollcommand=scrollbarx.set)
scrollbary.config(command=tree.yview)
scrollbary.pack(side=RIGHT, fill=Y)
scrollbarx.config(command=tree.xview)
scrollbarx.pack(side=BOTTOM, fill=X)
tree.heading('hora', text="hora", anchor=W)
tree.heading('temperatura', text="temperatura", anchor=W)
tree.column('#0', stretch=NO, minwidth=0, width=10)
tree.column('#1', stretch=NO, minwidth=0, width=40)
tree.pack()
tree.delete(*tree.get_children())
def lee():
try:
lectura = serial.Serial('COM3',9600)
lectura.timeout = 1
lectura.setDTR(False)
lectura.flushInput()
lectura.setDTR(True)
sArduino = lectura.readline()
sArduino = sArduino.strip()
sArduino=str(sArduino)
tiempo = time.time()
print (sTemp) # this works fine in real-time
hora=time.strftime("%H:%M:%S")
print(hora) # this works fine in real-time
tree.insert('','end', values=(hora,sTemp)) # doesnt work real-time
except:
messagebox.askquestion("Error")
def read ():
for i in range(5): # trying 5 times
ventanaLectura.after(2000,lee) # reads every 2 seg
thread = threading.Thread(target=read)
thread.start()
ventanaLectura.mainloop()
Моя вторая версия с theads и after function все еще не работает.данные (часы и температура) не отображаются в режиме реального времени в виде дерева, но работают с печатью в CLI.Как я могу просмотреть свои данные в графическом интерфейсе?Данные появляются только в конце.
Спасибо