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