【发布时间】:2011-08-19 17:46:17
【问题描述】:
我想将我的 GUI 中的标签更新为一种进度条,显示数据传输的完成程度。
无论我在哪里,人们都说要使用标签的textvariable 选项,然后设置字符串并更新标签。这对我不起作用。标签在数据收集循环结束时更新。我对深度编程知之甚少,但我想 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)
我的问题是:是否有某种命令可以实时更新 GUI 中的标签?
【问题讨论】:
-
我真的不认为这是一个好的欺骗;这个问题承认有几种解决方案并且是真正的背景,而这个问题有一个很好的解决方案。
标签: python while-loop tkinter