首页 > 解决方案 > 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-3.xuser-interfacetkinter

解决方案


推荐阅读