電路圖如下
接線如下
簡易的tkinter畫面
程式碼
from gpiozero import Buzzer,LED,Button
import tkinter as tk
from time import sleep
def yellow_win():
label.config(text="YELLOW",font=("Courier",26))
yellow.on()
bz.on()
sleep(1)
yellow.off()
bz.off()
def green_win():
label.config(text="GREEN",font=("Courier",26))
green.on()
bz.on()
sleep(1)
green.off()
bz.off()
def reset():
label.config(text="go!go!go!",font=("Courier",26))
bz=Buzzer(26)
yellow=LED(16)
green=LED(17)
btny=Button(13)
btng=Button(14)
btny.when_pressed=yellow_win
btng.when_pressed=green_win
root=tk.Tk()
root.geometry("640x480+640+300")
label=tk.Label(root,text="go!go!go!",font=("Courier",26))
label.place(x=160,y=50,width=320,height=200)
button=tk.Button(root,text="RESET",command=reset)
button.place(x=270,y=250,width=100,height=50)
root.mainloop()
留言列表