我正在使用树莓派,因为我需要一个GUI来显示我的LED闪光灯计数器项目。
我有错误IntVar()
它说它有属性错误__trunc__
这是我的代码:
import sys
import RPi.GPIO as GPIO
import time
import math
from Tkinter import *
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)
root = Tk()
root.geometry("200x200")
root.title("Simple Counter")
counter = IntVar()
def onClick1(event=None):
counter.set(counter.get()+1)
def onClick2(event=None):
counter.set(counter.get()-1)
def count():
for x in range(0, counter):
GPIO.output(16, True)
time.sleep(0.5)
GPIO.output(16, False)
entry = Entry(root, textvariable=counter).pack()
button = Button(root, text="Press to Add", command=onClick1).pack()
button2 = Button(root, text="Press to Subtract", command=onClick2).pack()
button3 = Button(root, text="Press to Continue", command=count).pack()
root.mainloop()
答案 0 :(得分:1)
问题在于:
for x in range(0, counter):
应该是
for x in range(0, counter.get()):
就像在onClick
函数中一样。