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

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()
Reply
#2
Change line 50 to win.mainloop().
Post the next the the stack trace.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020