# WATER SW(PUMP) test -2024.1.18- import tkinter as tk import threading as th import RPi.GPIO as GPIO import time # I/O (GPIO pin) SOLENOID = 25 # initialize GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) # init:SOLENOID OFF GPIO.setup(SOLENOID, GPIO.OUT, initial=GPIO.LOW) root = tk.Tk() root.geometry('300x140+100+50') root.title('給水スイッチ') tx = tk.StringVar() tx.set('WATER OFF') label = tk.Label(root, textvariable = tx) label.place(x=160, y=55) def act(): tx.set('WATER ON') GPIO.output(SOLENOID, GPIO.HIGH) t = th.Timer(5, act2) t.start() def act2(): GPIO.output(SOLENOID, GPIO.LOW) tx.set('WATER OFF') button = tk.Button(root, text = 'SW', command = act) button.place(x=100, y=50) root.mainloop()