我试图创建一个从arduino A0引脚连续读取模拟数据的开始按钮和一个停止读取数据的停止按钮。这必须更新为标签。这是我的代码:
from tkinter import *
import time
import serial
import serial.tools.list_ports
ports = list(serial.tools.list_ports.comports())
for p in ports:
print (p)
if "Serial Device" in str(p):
print("Connect here!")
wor=str(p)
w=wor[:4]
print(w)
ser = serial.Serial(w, 9600)
root = Tk()
root.maxsize(600,380)
v=StringVar()
def rd():
while 1:
value = ser.readline()
val = value.decode('utf8')
v.set(val)
def nord():
ser.close()
start=Button(root,text="start",command=rd).place(x=225,y=300)
stop=Button(root,text="stop",command=nord).place(x=325,y=300)
T = Label(root, textvariable=v,bg="white").place(x=238,y=100)
root.mainloop()