当我运行我的 tkinter 代码以使用 Adafruit 测量温度时。当我运行我的代码时,tkinter 打开一个窗口,但窗口上没有任何内容。我以前使用过 tkinter,我已经看到了应该出现的东西,但只是没有出现在这个特定的代码中。
#!/usr/bin/python
# -*- coding: latin-1 -*-
import Adafruit_DHT as dht
import time
from Tkinter import *
root = Tk()
k= StringVar()
num = 1
thelabel = Label(root, textvariable=k)
thelabel.pack
def READ():
h,t = dht.read_retry(dht.DHT22, 4)
newtext = "Temp=%s*C Humidity=%s" %(t,h)
k.set(str(newtext))
print newtext #I added this line to make sure that newtext actually had the values I wanted
def read30seconds():
READ()
root.after(30000, read30seconds)
read30seconds()
root.mainloop()
并澄清 READ 中的打印行确实按预期运行了 30 秒。