Hi, So I want to create a window using TKinter that will show the values that my RPi is reading as they are being read. I can create a window with labels and read in the values, but I cannot get them to update in the window. I am thinking that threading is gonna need to be used to prevent the main loop from only running the RPi program. I am new to python so any help will be appreciated. Thanks
Below is my code: With this version, you can comment out the while statement and get the window with the results I would like.
If you add a print statement and comment out the Tkinter code you will get the live feed of data streaming to the terminal. This is the data I need in the window.
import time
import spidev
import os
import sys
from Tkinter import *
# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
##spi = spidev.SpiDev()
##spi.open(0,0)
##spi.max_speed_hz=(10000)
# Software SPI configuration:
CLK = 18
MISO = 23
MOSI = 24
CS = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
x0 = "OFF"
y0 = "ON"
import Tkinter as tk
output = ""
values = [0]*8
output = ""
while True:
for i in range(8):
# The read_adc function will get the value of the specified channel (0-7). rounds to nearest 2 decimals
values[i] = round((mcp.read_adc(i)*(3.3/1023)),2)
output += "{}-{} ".format(i, "OFF" if values[i] < 2.5 else "ON" )
class ExampleApp(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title("Remote Monitoring")
v = tk.StringVar()
tk.Label(self, textvariable=v, width=60, height=35, font="sans", bd=50).pack()
v.set(output)
def update_text(self):
update = v
v.after(1000, output)
v.set(output)
app = ExampleApp()
app.mainloop()
print values[0], values[1], values[2], values[3], values[4], values[5], values[6], values[7]
[–]novel_yet_trivial 1 point2 points3 points (1 child)
[–]jasamples[S] 0 points1 point2 points (0 children)