1

第一次发帖。我是一个写python程序的新手。我想诅咒显示连接到 Raspberry PI 的传感器的输出,并创建以下代码作为测试以了解它需要以何种方式编码,但是我无法显示 CPU 温度?

import curses
from curses import wrapper
from gpiozero import CPUTemperature

print("Preparing to initialize screen...")

screen = curses.initscr()

print("Screen initialized.")

first_window = curses.newwin(15, 20, 0, 0)

cpu = CPUTemperature()

print(int(cpu.temperature))

def main(test):

# Update the buffer, adding text at different locations
    first_window.addstr(1, 1, "CPU Temperature")
    first_window.addch(2, 1, int(cpu.temperature))
    first_window.refresh()
    curses.napms(5000)
    
wrapper(main)

curses.endwin()

print("Window ended.")

感谢阅读,感谢帮助

4

0 回答 0