【发布时间】:2015-07-10 18:02:18
【问题描述】:
我编写了一个代码来从我的 arduino 读取模拟值并在一个简单的 Python 应用程序中监控结果,但是当我在我的应用程序中点击“开始”按钮时,出现了这个错误:Tkinter 回调中的异常 Traceback(最近一次通话最后一次)
并且编译器在这个指令中找到了错误:analoglabel.config(text=str(pin.read()))
抱歉,我无法填写所有错误信息
这是我的代码:
import pyfirmata
from pyfirmata import util
import Tkinter
from time import sleep
def press():
it = util.Iterator(board)
it.start()
while True:
if flag.get():
analoglabel.config(text=str(pin.read()))
analoglabel.update_idletasks()
root.update()
else:
break
board.exit()
root.destroy()
def exit_command():
flag.set(False)
port = '/dev/ttyACM0'
board = pyfirmata.Arduino(port)
sleep(5)
pin = board.get_pin('a:0:i')
root = Tkinter.Tk()
root.title("Analog read by hamzawi")
root.minsize(300, 50)
startbutton = Tkinter.Button(root,
text="START",
command=press)
startbutton.grid(column=1, row=2)
exitbutton = Tkinter.Button(root,
text="EXIT",
command=exit_command)
exitbutton.grid(column=2, row=2)
label = Tkinter.Label(root,
text="The value is: ")
label.grid(column=1, row=1)
analoglabel = Tkinter.Label(root, text=" ")
analoglabel.grid(column=2, row=1)
flag = Tkinter.BooleanVar()
flag.set(True)
root.mainloop()
我需要帮助!!非常感谢
【问题讨论】:
-
您好,欢迎来到 StackOverflow。请花一些时间阅读帮助页面,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。更重要的是,请阅读the Stack Overflow question checklist。您可能还想了解Minimal, Complete, and Verifiable Examples。
-
您必须告诉我们实际的错误,我们才能为您提供帮助。
-
这里是第 1 部分,因为它很长:Tkinter 回调回溯中的异常(最近一次调用最后一次):文件“/usr/lib/python2.7/lib-tk/Tkinter.py”,第 1489 行,在 call 中返回 self.func(*args) 文件“/home/hamzawi/Documents/Python_projects/potentioPython/pot.py”,第 13 行,按analoglabel.config(text=str(val) )
-
这是第 2 部分:文件“/usr/lib/python2.7/lib-tk/Tkinter.py”,第 1274 行,在配置中返回 self._configure('configure', cnf, kw)文件“/usr/lib/python2.7/lib-tk/Tkinter.py”,第 1265 行,在 _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf) ) TclError: 无效的命令名“.3065381132L”
-
@HamzaBoughraira:请编辑您的问题以包含该信息。无法在评论中阅读。
标签: python python-2.7 tkinter arduino firmata