我想在GUI中更新Label作为一种进度条,显示数据传输的完整程度.
我看到的每个地方,人们都说要使用textvariableLabel选项,然后设置字符串和标签更新.这对我不起作用.标签在数据收集循环结束时更新.我不太了解编程的深度,但我想,在完成数据收集循环而不是中间循环之后,Python才会刷新Tkinter.
这是数据收集循环:
def getdata(self, filename):
data=[]
count=0
percentage=0
self.ser.write('$get\r\n')
total=int(self.ser.readline().split()[0])
line=self.ser.readline()
while line != '':
data.append(line)
count+= 1
if percentage != str(round(float(count)/total,2)):
menu.percentage.set(str(round(float(count)/total,2)*100)+'% Completed')
#^^^menu.percentage is the textvariable of the Label I want updated^^^#
print str(round(float(count)/total,2)*100)+'% Completed'
percentage = str(round(float(count)/total,2))
line=self.ser.readline()
outfile=open(filename, 'w')
outfile.writelines(data)
Run Code Online (Sandbox Code Playgroud)
我的问题是:是否有某种命令会实时更新GUI中的Label?