import tkinter as tk import threading as th import time import RPi.GPIO as GPIO # initialize GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) RELAY = 21 # 初期状態:RELAY(PUMP) OFF GPIO.setup(RELAY, GPIO.OUT, initial=GPIO.LOW) root = tk.Tk() tx = tk.StringVar() tx.set('水補給時に押す。') root.geometry('600x400') root.title('給水装置') label = tk.Label(root, textvariable = tx) label.place(x=300, y=185) def act(): tx.set('5秒注水!') GPIO.output(RELAY, GPIO.HIGH) t = th.Timer(5, act2) t.start() def act2(): tx.set('水補給時に押す。') GPIO.output(RELAY, GPIO.LOW) button = tk.Button(root, text = '注水ボタン', command = act) button.place(x=200, y=180) root.mainloop()