Sep-17-2018, 08:29 PM
Hi there! I am new to python but have mild experience with C and Java. The code below is not working for me because of something in the Python. I am taking a simple GUI example and mixing it with a simple temperature retrieving script.
GUI Code: https://educ8s.tv/raspberry-pi-gui-tutor...nd-python/
Temperature code: http://www.circuitbasics.com/how-to-set-...pberry-pi/
What I have done: I added to the temperature by making temperaturef which converts temperature © to (F). Then I placed it into the example GUI's code.
Objective: I want to display the temperature output into the GUI.
What am I missing with properly inputting Tkinter text, and is there a resource with code for it? (I looked around a bit but didn't find a definitive list of commands like button used below in the example.
Thank you~
GUI Code: https://educ8s.tv/raspberry-pi-gui-tutor...nd-python/
Temperature code: http://www.circuitbasics.com/how-to-set-...pberry-pi/
What I have done: I added to the temperature by making temperaturef which converts temperature © to (F). Then I placed it into the example GUI's code.
Objective: I want to display the temperature output into the GUI.
What am I missing with properly inputting Tkinter text, and is there a resource with code for it? (I looked around a bit but didn't find a definitive list of commands like button used below in the example.
Thank you~
from Tkinter import * import tkFont import RPi.GPIO as GPIO import sys import Adafruit_DHT humidity, temperature = Adafruit_DHT.read_retry(11, 4) temperaturef = temperature * 1.8 temperaturef = temperaturef + 32 GPIO.setmode(GPIO.BOARD) GPIO.setup(40, GPIO.OUT) GPIO.output(40, GPIO.LOW) win = Tk() myFont = tkFont.Font(family = 'Helvetica', size = 36, weight = 'bold') def ledON(): print("LED button pressed") if GPIO.input(40) : GPIO.output(40,GPIO.LOW) ledButton["text"] = "LED ON" else: GPIO.output(40,GPIO.HIGH) ledButton["text"] = "LED OFF" def exitProgram(): print("Exit Button pressed") GPIO.cleanup() win.quit() win.title("First GUI") win.geometry('800x480') exitButton = Button(win, text = "Exit", font = myFont, command = exitProgram, height = 2, width = 6) exitButton.pack(side = BOTTOM) ledButton = Button(win, text = "LED ON", font = myFont, command = ledON, height = 2, width = 8) ledButton.pack() while True: TempLine = Text(win, height = 2, width = 6) TempLine.pack() TempLine.insert('Temp: {0:0.1f}C Temp: {1:0.1f}F Humidity: {1:0.1f}%' .format(temperature, temperaturef, humidity)) continue mainloop()