我的文本窗口小部件未更新。我使用来自Android手机的串行通讯,并通过bt模块接收。请帮忙。我尝试使用after(time,function_name),但是什么也没有发生。谁能告诉我这段代码有什么问题。我想我忘了一些东西。谢谢。这是我的密码
from serial import *
from tkinter import *
serialPort = "/dev/ttyAMA0"
baudRate = 9600
bluetoothSerial = Serial(serialPort , baudRate, timeout=1)
app = Tk()
app.wm_title("Wireless Notice Board")
scrollbar = Scrollbar(app)
scrollbar.pack(side=RIGHT, fill=Y)
serBuffer = ""
def readSerial_data():
while True:
z = bluetoothSerial.readline().decode()
if len(z) == 0:
break
global serBuffer
if z == '\r':
z = ''
if z == '\n':
serBuffer += "\n"
#datalog.insert('0.0', text_data)
serBuffer = ""
print(z)
else:
if z == "CLEAR":
datalog.delete('1.0', END)
else:
def split():
while True:
a,b,c,d,e = z.split(',')
datalog = Text (app, width=200, height=50,bg = e, foreground = c, takefocus=0, font = (b, 32))
datalog.pack()
datalog.insert('0.0', a)
serBuffer += a
print(a)
print(b)
print(c)
print(d)
print(e)
datalog.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=datalog.yview)
app.after(10, split)
app.after(100, split)
app.after(10, readSerial_data)
app.after(100, readSerial_data)
app.mainloop()