-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
56 lines (49 loc) · 1.5 KB
/
gui.py
File metadata and controls
56 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import pygame
import sys
from read import read
from datetime import datetime
import board
import adafruit_dht
import time
# Pygameの初期化
pygame.init()
dhtDevice = adafruit_dht.DHT22(board.D18)
# フルスクリーンモード
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) # フルスクリーンに設定
pygame.display.set_caption("常設app")
# 画面の幅と高さを取得
screen_width, screen_height = screen.get_size() #1360 768
font_path = "data/SourceHanSans-VF.ttf"
font = pygame.font.Font(font_path, 60)
bfont = pygame.font.Font(font_path, 200)
pygame.mouse.set_visible(False)
# 色
white = (255, 255, 255)
black = (0, 0, 0)
# テキスト描画関数
def draw_text(text, font, color, surface, x, y):
label = font.render(text, True, color)
surface.blit(label, (x - label.get_width() // 2, y - label.get_height() // 2))
# メインゲームループ
running = True
air=""
while running:
now = datetime.now()
try:
temperature_c = dhtDevice.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = dhtDevice.humidity
air=f"{temperature_c}C {humidity}% "
except:
pass
screen.fill(white) # 画面を白で塗りつぶす
date=now.strftime("%Y-%m-%d")
ttime=now.strftime("%H:%M %S")
draw_text(date, font, black, screen,680, 100)
draw_text(ttime, bfont, black, screen,680, 384)
draw_text(air, font, black, screen,680, 670)
pygame.display.flip()
time.sleep(0.1)
# Pygame終了
pygame.quit()
sys.exit()