【发布时间】:2016-06-06 21:48:05
【问题描述】:
Python 新手,开始使用 DHT11 温度/湿度传感器、Raspberry Pi 3 和 Python 3。
我使用 Python 的标准 Adafruit DHT11 Library。
从 GPIO 27 读取
我能够在 GUI 窗口中显示温度就好了。我坚持的是如何让 GUI 以设定的速率更新/刷新温度,因此它是当前温度的“实时”显示。现在,如果我关闭并重新打开我的脚本,我只能从 GUI 获得更改。请参阅下面的代码:
from tkinter import *
import tkinter.font
import Adafruit_DHT
temp = 0
win = Tk()
win.title("Temperature")
win.geometry("100x100")
def READ():
global temp
humidity, temperature = Adafruit_DHT.read_retry(11, 27)
temp = temperature * 9/5.0 + 32
Label (win, text=str(temp), fg="black", bg="white", font="36").grid(row=0, column=0)
if (temp >= 0):
READ()
mainloop()
【问题讨论】: