Mar-16-2017, 02:10 PM
So I have been struggling for awhile now trying to display a variable value to a label. I have a loop setup to read an ADC value, translate that value back to a Pressure value ( I am reading a 4-20 mA signal from a dP sensor ) then print the current pressure value to label "CurrentLabel2" . No matter what I try it either does not work at all or just displays Pi_Var3 or something of the sort. I have imported my entire script below. I have almost no programming experience and am just working on this for fun to expand my knowledge. In short, I want the variable "x_Input" to display on "CurrentLabel2" and I am not sure how to do so. I have tried setting the "textvariable" command.
from Tkinter import* import Tkinter as tk from decimal import* from time import* from time import sleep import RPi.GPIO as GPIO import sys import Adafruit_ADS1x15 import threading GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.setup(11, GPIO.IN) root=tk.Tk() root.title("Test Room dP Controller") root.geometry('800x480') #uncomment the next line when ready to use with touchscreen. #root.config(cursor='none') # Establishing global variables. x is a translation from dP to Voltage # in order to compare the Voltage input by the dP sensor to what the user wants. # Entry_Output is just the value the slider is set to. Entry_Output = tk.IntVar() x = tk.IntVar() ADC_Value = tk.IntVar() x_Input = tk.IntVar() adc = Adafruit_ADS1x15.ADS1115() GAIN = 1 Spacer = tk.Label(root, height = 5).grid(row=1, column=1, columnspan =3) # Setting the location for a slider scale. DesiredEntry= tk.Scale(root, from_= -0.2, to = 0.2 , tickinterval=0.05, resolution=0.05, orient = 'horizontal', font="Verdana 12", length=550, width=50) DesiredEntry.grid(row=2,column=2) DesiredEntryLabel = tk.Label(root, text = "Desired dP", font = "Verdana 18") DesiredEntryLabel.grid(row = 2, column = 1) UnitLabel= tk.Label(root, text= "inH2O", font="Verdana 12").grid(row=2,column=3) # Establishing the variable "Entry_Output" as a modular level variable # to pull the entry from the function 'PullData'. def PullData(Entry_Output, x): Entry_Output = DesiredEntry.get() x = ((DesiredEntry.get()+0.25)/(1/2.4)) print(x) def callback(): while True: ADC_Value = adc.read_adc_difference(0,gain = GAIN) print(ADC_Value, "ADC Value") sleep(2) x_Input = (((ADC_Value-68)*(1/8002.0))*(1/2.4))-0.25 print(x_Input, "Current Pressure") t = threading.Thread(target = callback) t.start() Spacer2 = tk.Label(root, height = 2).grid(row=3,column=1,columnspan=3) # Setting the location for a display. CurrentLabel= tk.Label(root, text= "Current dP", font="Verdana 18").grid(row=4,column=1) CurrentLabel2= tk.Label(root, font = "Verdana 20", width= 32, height= 1, relief= SUNKEN) CurrentLabel2.grid(row=4,column=2) UnitLabel2= tk.Label(root, text= "inH2O", font="Verdana 12").grid(row=4,column=3) Spacer3 = tk.Label(root, height = 5).grid(row=5,column=1,columnspan=3) # Setting the location for the button controls. ButtonFrame= tk.Frame(root) ButtonFrame.grid(row=6, column=1, columnspan=3) B1 = tk.Button(ButtonFrame, text="Start", width=27, height= 3, font="Verdana 10 bold", activebackground='green', command = lambda:PullData(Entry_Output, x)).grid(row=6, column=1) B2 = tk.Button(ButtonFrame, text = "Shutdown", width=27, height=3, font="Verdana 10 bold", activebackground = 'red').grid(row = 6, column = 2) B3 = tk.Button(ButtonFrame, text="Close", width=27, height= 3, command=root.destroy, font="Verdana 10 bold", activebackground='red').grid(row=6,column=3) root.mainloop()