進度條可以讓使用者可以更容易的知道目前工作的進度。以下程式碼為一個簡單的範例:
oDesktop.ClearMessages('', '', 2)
import time
import threading
t0 = time.time()
def func(x, result):
data = []
for j in range(x, x + 1000):
data.append(j)
x = sum(data)
result.append(str(x))
def progressbar(x):
if 0 <= x <= 100:
i = x // 2
j = x % 2
if j == 0:
AddWarningMessage(u"\u2588" * (i) + u"\u2581" * (50 - i) + '[{:4}%]'.format(x))
else:
AddWarningMessage(u"\u2588" * (i) + u"\u2585" + u"\u2581" * (49 - i) + '[{:4}%]'.format(x))
else:
pass
result = []
threads = []
for i in range(101):
t = threading.Thread(target=func, args=(i, result))
t.start()
threads.append(t)
progressbar(i)
for i in threads:
t.join()
AddWarningMessage(str(result))
AddWarningMessage(str(time.time() - t0) + '(secs)')
(圖一)進度條範例 |
沒有留言:
張貼留言