Jan-05-2023, 10:24 PM
Hi all... I am not sure why, but this code is no longer executing the GUI like it once did. The code runs fine, the 'Print' line shows up fine in the terminal, the data gets logged from the sensor in the text file, but I get no Tkinter window? Please help.... Not sure where I am going wrong.
from tkinter import * import time import datetime import bme280 import smbus2 from smbus2 import SMBus from smbus import SMBus from bme280 import BME280 root = Tk() root.title('Humidity Logger') root.configure(background='white') root.geometry("500x300") bus = SMBus(1) bme280 = BME280(i2c_dev=bus) bme_label = Label(root, text = "bme280", fg = "green", bg = "white", font = ("Helvetica", 32)) bme_label.pack(pady = 35) while True: now = datetime.datetime.now() temperature = bme280.get_temperature() humidity = bme280.get_humidity() pressure = bme280.get_pressure() tempf = float(temperature * 9.0 / 5.0) + 32.0 print(now.strftime("%m-%d-%Y %H:%M:%S") + ' | Temperature(*F/*C): {:.2f}*F | {:05.2f}*C | Humidity: {:05.2f}% | Pressure: {:05.2f}hPa'.format(tempf,temperature,humidity,pressure)) bme_label.configure(text='Temp(*F): {:.2f}*F | Humidity: {:05.2f}%'.format(tempf,temperature,humidity)) FileName = str("/home/pi/BME280_DataLog.txt") with open(FileName, "a") as f: f.write(now.strftime("%m-%d-%Y %H:%M:%S") + ' | Temperature(*F/*C): {:.2f}*F | {:05.2f}*C | Humidity: {:05.2f}% | Pressure: {:05.2f}hPa'.format(tempf,temperature,humidity,pressure) + '\n') time.sleep(10) root.mainloop()