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()
。