Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Raspberry Pi GUI
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:
Temperature code:

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.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) :
		ledButton["text"] = "LED ON"
                ledButton["text"] = "LED OFF"

def exitProgram():
	print("Exit Button pressed")

win.title("First GUI")

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)

while True:
    TempLine = Text(win, height = 2, width = 6)
    TempLine.insert('Temp: {0:0.1f}C Temp: {1:0.1f}F Humidity: {1:0.1f}%' .format(temperature, temperaturef, humidity))

Change line 50 to win.mainloop().
Post the next the the stack trace.
My code examples are always for Python >=3.6.0
Almost dead, but too lazy to die:
All humans together. We don't need politicians!

Top Page

Forum Jump:

Users browsing this thread: 1 Guest(s)