简体   繁体   English

在Python的列表理解中插入tkinter进度栏

[英]insert a tkinter progress bar in a List Comprehensions of Python

Normally i use a simple loop to insert a indeterminate progress bar in tkinter. 通常我使用一个简单的循环在tkinter中插入一个不确定的进度条。 example

self.pbar_ind = ttk.Progressbar(self, orient="horizontal", length=300, mode="indeterminate")

new_point_in_list = list()
for point in point_in_list:
  self.pbar_ind.step(1)
  self.update()
  if point > 2:
     new_point_in_list.append(point)

Now i am using a List Comprehensions to speed my computation 现在我正在使用列表推导来加快计算速度

new_point_in_list = [point for point in point_in_list if point > 2]

i wish to know if it possible to insert in the List Comprehensions the Tkinter progress bar 我想知道是否可以在列表理解中插入Tkinter进度条

If you are concerned about performance, remove the call to self.update() . 如果您担心性能,请删除对self.update()的调用。 It will slow your loop down by up to three orders of magnitude . 它将使您的循环速度降低多达三个数量级 At the very least you should call it only every 1,000 iterations or so. 至少您应该仅每1,000次迭代调用一次。

In a quick test, I can do 10,000 simple calculations that result in 1% of the values being appended to a loop in about .0016 seconds. 在快速测试中,我可以进行10,000个简单的计算,从而导致大约0.016秒内将1%的值附加到循环中。 When I add a call to update in the loop, the time expands to 1.0148 seconds. 当我在循环中添加要update的呼叫时,时间将扩展为1.0148秒。

You said in a comment you have 80 million rows to iterate over. 您在评论中说,您有八千万行要迭代。 My same code can process 80 million calculations in 12 seconds , versus over 2 hours when I add in a call to update. 我的相同代码可以在12秒内处理8000万次计算,而在我添加更新调用时要花2个小时以上。

Converting your code to using a list comprehension will have a negligible effect compared to removing or reducing the calls to update. 与删除或减少对更新的调用相比,将您的代码转换为使用列表理解将具有微不足道的效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM