zoukankan      html  css  js  c++  java
  • Python tkinter 进度条代码

     1 import tkinter as tk
     2 import time
     3 
     4 # 创建主窗口
     5 window = tk.Tk()
     6 window.title('进度条')
     7 window.geometry('630x150')
     8 
     9 # 设置下载进度条
    10 tk.Label(window, text='下载进度:', ).place(x=50, y=60)
    11 canvas = tk.Canvas(window, width=465, height=22, bg="white")
    12 canvas.place(x=110, y=60)
    13 
    14 
    15 # 显示下载进度
    16 def progress():
    17     # 填充进度条
    18     fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
    19     x = 500  # 未知变量,可更改
    20     n = 465 / x  # 465是矩形填充满的次数
    21     for i in range(x):
    22         n = n + 465 / x
    23         canvas.coords(fill_line, (0, 0, n, 60))
    24         window.update()
    25         time.sleep(0.02)  # 控制进度条流动的速度
    26 
    27     # 清空进度条
    28     fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="white")
    29     x = 500  # 未知变量,可更改
    30     n = 465 / x  # 465是矩形填充满的次数
    31 
    32     for t in range(x):
    33         n = n + 465 / x
    34         # 以矩形的长度作为变量值更新
    35         canvas.coords(fill_line, (0, 0, n, 60))
    36         window.update()
    37         time.sleep(0)  # 时间为0,即飞速清空进度条
    38 
    39 
    40 btn_download = tk.Button(window, text='启动进度条', command=progress)
    41 btn_download.place(x=400, y=105)
    42 
    43 window.mainloop()
  • 相关阅读:
    简单理解jQuery中$.getJSON、$.get、$.post、$.ajax用法
    适配器模式(Adapter Pattern)
    什么样的登录框才算是优秀的?
    transient的作用及序列化
    MySQL索引实现原理
    concurrentHashMap原理分析和总结(JDK1.8)
    HashMap实现原理(JDK1.8)
    深入理解Java中的IO
    多线程系列
    多线程系列
  • 原文地址:https://www.cnblogs.com/lize19940412/p/14780881.html
Copyright © 2011-2022 走看看