python-3.x - Tkinter GUI 小部件挂起(输入通过超链接/串行连续发送)
问题描述
from tkinter import *
from serial import Serial
import sys
import binascii
from queue import Queue
import time
ser = Serial('COM3', 9600, timeout=1)
通过 USB
读取获取串行输入是全局的,因此可以在 update_reading 函数中访问
global read
reading = ser.read(8).hex()
read=reading
root=Tk()
root.geometry('500x500')
root.configure(bg='#ffffff')
创建 TextBox 以便可以将解决方案放置在那里
e=Entry(root,width=35,borderwidth=5)
e.grid(row=0, column=0,columnspan=3,padx=10,pady=10)
更新到下一个序列值
def update_reading():
b=ser.read(8).hex()
if read==b:
update_reading()
else:
reading=a
button_click(a)
def button_click(read):
e.delete(0,END)
e.insert(0,read)
update_reading()
单击按钮时,它会在文本框中打印值
myButton=Button(root,text="Output Values",command=lambda:button_click(reading))
myButton.grid(row=0,column=5,padx=10,pady=0)
root.mainloop()
解决方案
推荐阅读
- python - TypeError:需要一个类似字节的对象,而不是'_io.BytesIO' | 姜戈 | 枕头
- c# - 尝试使用 wsdl.exe 创建 C# 代码时出错
- python - Fastapi python代码执行速度受uvicorn vs gunicorn部署的影响
- c# - 在最近的空闲位置向数组添加元素
- real-time-clock - 关于12057 RTC精度
- javascript - NextJS - 我可以构建一个使用路径或查询参数的系统吗?
- android - ManifestMerger 因多个错误而失败
- python - Pytest 中类范围固定装置的意外行为
- javascript - 如何修复错误“无法读取未定义的属性‘statusText’”
- docker - 运行我的开发应用程序时,我应该何时使用 Docker(本地)?