1
我是一個開始與Python,並決定給它一個我的覆盆子pi去。我學會了Python從一本小書,涵蓋了基礎知識,結合我演示更改與切換按鈕和照明瞭LED的Tkinter的窗口背景色來得到這個代碼:蟒蛇GPIO引腳不會清理
#! /usr/bin/env python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD); GPIO.setup(7, GPIO.OUT)
GPIO.output(7, False)
from Tkinter import*
window = Tk()
window.title("Relay Button")
window.configure(bg= "green")
btn_end= Button(window, text = "close", command=exit)
def tog():
if (GPIO.input(7) == True):
GPIO.output(7, False)
else:
GPIO.output(7, True)
btn_tog=Button(window, text="Switch", command=tog)
btn_end.pack(padx=100, pady=20)
btn_tog.pack(padx=100, pady=20)
window.mainloop()
GPIO.cleanup()
我得到的錯誤:
relaybutton.py:3: RuntimeWarning: This channel is already in use,
continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
GPIO.setmode(GPIO.BOARD); GPIO.setup(7, GPIO.OUT)
我不知道爲什麼我得到這個錯誤,我在最後的GPIO.cleanup()
。