# 設置下載進度條
tk.Label(window, text='下載進度:').place(x=40, y=80)
canvas = tk.Canvas(window, width=600, height=16, bg="white")
canvas.place(x=20, y=90)
# 下載按鈕函數
def usr_download():
response = session.get(url_str, headers=headers2, cookies=cookies_xxx, verify=False, stream=True) # stream=True表示請求成功后并不會立即開始下載,而是在調用iter_content方法之后才會開始下載
chunk_size = 40960 # 設置每次下載的塊大小
content_size = int(m4a.headers['content-length']) # 從返回的response的headers中獲取文件大小
# 填充進度條
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
raise_data = 600 / (content_size/chunk_size) # 增量大小,600為進度條的長度
# 將下載的數據寫入文件
with open(title + '.m4a', 'wb') as f:
n = 0
for data in response.iter_content(chunk_size=chunk_size): # 在循環讀取文件時,刷新進度條
f.write(data)
n = n + raise_data
canvas.coords(fill_line, (0, 0, n, 60))
window.update()
# 清空進度條
def clean_progressbar():
# 清空進度條
fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="white")
x = 500 # 未知變量,可更改
n = 600 / x # 465是矩形填充滿的次數
for t in range(x):
n = n + 600 / x
# 以矩形的長度作為變量值更新
canvas.coords(fill_line, (0, 0, n, 60))
window.update()
# 下載按鈕
btn_download = tk.Button(window, text='開始下載', command=usr_download)
btn_download.place(x=600, y=28)
https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=6832178122364816644
以上就是python tkinter實現下載進度條及抖音視頻去水印原理的詳細內容,更多關于python 下載進度條及抖音視頻去水印的資料請關注腳本之家其它相關文章!