我在Jetson Nano上运行了这个Kivy代码。MLX90614是连接到i2c的温度传感器。一旦运行,它将显示温度,但它不会更新/刷新。怎样才能让它不断地显示实际温度呢?
代码如下:
from kivy.app import App
from kivy.uix.label import Label
import board
import busio as io
import adafruit_mlx90614
i2c = io.I2C(board.SCL, board.SDA, frequency=100000)
mlx = adafruit_mlx90614.MLX90614(i2c)
class MainApp(App):
def build(self):
label = Label(text='This is the temperature: ' + str(mlx.object_temperature),
size_hint=(.5, .5),
pos_hint={'center_x': .5, 'center_y': .5})
return label
if __name__ == '__main__':
app = MainApp()
app.run()结果如下:

发布于 2020-11-13 07:03:57
如下所示:
from kivy.clock import Clock
class MainApp(App):
def build(self):
self.label = Label(text='This is the temperature: ' + str(mlx.object_temperature),
size_hint=(.5, .5),
pos_hint={'center_x': .5, 'center_y': .5})
Clock.schedule_interval(self.update_label, 0)
return self.label
def update_label(self, dt):
self.label.text = "This is the temperature: {}".format(mlx.object_temperature)https://stackoverflow.com/questions/64812818
复制相似问题