#!/usr/bin/env python # max6675Tkinter.py # rename this to a py file from a text file. # by Lewis Loflin lewis@bvu.net # www.bristolwatch.com from Tkinter import * # import tkinter everything #import Tkinter must start with capital 'T' for python 2.7 import os # access system commands class App: def __init__(self, master): frame = Frame(master) frame.pack() Label(frame, text="MAX6675 Thermal Couple Sensor").grid(row=0, columnspan=2) self.result_var = DoubleVar() Entry(frame, textvariable=self.result_var).grid(row=1, columnspan=4) button0 = Button(frame, text="Temp F", command=self.readMAX6675) button0.grid(row=2, columnspan=4) def readMAX6675(self): f = os.popen("sudo /root/work/MAX6675") s1 = f.read() # will return a string such as # S 97 C = 24.25 F = 75.65 print s1 pos1 = 0 pos1 = s1.find('C = ') print "Char C is at position ", pos1 pos2 = 0 pos2 = s1.find('F = ') print "Char F is at position ", pos2 Sensor = int(s1[2:pos1 - 1]) print "Sensor value = ", Sensor degC = float(s1[pos1+3 : pos2-1]) print "Degrees C = ", degC degF = float(s1[pos2+3 : len(s1)]) print "Degrees F = ", degF self.result_var.set(degF) root = Tk() root.wm_title("Read MAX6675 Sensor") app = App(root) root.mainloop()