首页 > 其他 > 详细

thkiner常用组件

时间:2020-12-12 23:36:36      阅读:41      评论:0      收藏:0      [点我收藏+]

目录

进度条

import tkinter as tk
import time

# 创建主窗口
window = tk.Tk()
window.title(‘进度条‘)
window.geometry(‘630x150‘)

# 设置下载进度条
tk.Label(window, text=‘下载进度:‘, ).place(x=50, y=60)
canvas = tk.Canvas(window, width=465, height=22, bg="white")
canvas.place(x=110, y=60)


# 显示下载进度
def progress():
    # 填充进度条
    fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="green")
    x = 500  # 未知变量,可更改
    n = 465 / x  # 465是矩形填充满的次数
    for i in range(x):
        n = n + 465 / x
        canvas.coords(fill_line, (0, 0, n, 60))
        window.update()
        time.sleep(0.02)  # 控制进度条流动的速度

    # 清空进度条
    fill_line = canvas.create_rectangle(1.5, 1.5, 0, 23, width=0, fill="white")
    x = 500  # 未知变量,可更改
    n = 465 / x  # 465是矩形填充满的次数

    for t in range(x):
        n = n + 465 / x
        # 以矩形的长度作为变量值更新
        canvas.coords(fill_line, (0, 0, n, 60))
        window.update()
        time.sleep(0)  # 时间为0,即飞速清空进度条


btn_download = tk.Button(window, text=‘启动进度条‘, command=progress)
btn_download.place(x=400, y=105)

window.mainloop()

thkiner常用组件

原文:https://www.cnblogs.com/zhaobowen/p/14127220.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!