我怎样才能解决这个__trunc__错误?

时间:2016-03-08 16:53:32

标签: python-3.x tkinter truncate

我正在使用树莓派,因为我需要一个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()

1 个答案:

答案 0 :(得分:1)

问题在于:

for x in range(0, counter):

应该是

for x in range(0, counter.get()):

就像在onClick函数中一样。