tkinter
我想知道tkinter中的按钮处理一个长时间的事件时,弹出progressbar进度条,然后事件处理完后进度条关闭,怎么实现。麻烦给个实例,谢谢! 没写过 {:10_289:}
https://github.com/jishansingh/HackTrix-Proj/blob/023d5835742d5f1da8db66333aecce13660cd983/pyDownloader/downloader.py
帮你用GitHub搜索的 这个看起来还不错 你也可以自己搜 kogawananari 发表于 2021-8-27 15:43
没写过
https://github.com/jishansingh/HackTrix-Proj/blob/023d5835742d5f1da8db66333aecc ...
丝~~,有点难看懂,大佬能简单说一下您的思路吗 py.c.c++ 发表于 2021-8-27 15:57
丝~~,有点难看懂,大佬能简单说一下您的思路吗
看得懂我就自己给你写了 不用去搜别人的
我只能看出是分chunk下载的 下载的线程把chunk的进度传给渲染的线程{:10_263:} kogawananari 发表于 2021-8-27 16:21
看得懂我就自己给你写了 不用去搜别人的
我只能看出是分chunk下载的 下载的线程把chunk的进度传给渲染 ...
我的意思是对于我的问题,大佬有没有一点思路,怎么实现 py.c.c++ 发表于 2021-8-27 19:10
我的意思是对于我的问题,大佬有没有一点思路,怎么实现
你整个假的进度条就很简单异步下载开始的时候启动进度条 下完了回调的时候把进度条关了
你要搞真进度条就很难 要算字节的{:10_293:} 本帖最后由 qq1151985918 于 2021-8-27 22:37 编辑
给你敲一个简单案例from tkinter import ttk
from tkinter import *
from threading import Thread
from time import sleep
def task():
sleep(3)
def test():
def show_prog():
top = Toplevel()
top.attributes("-toolwindow", 1)
top.wm_attributes("-topmost", 1)
top.title("进度条")
Label(top, text="正在执行任务,三秒后关闭进度条…").pack()
prog = ttk.Progressbar(top, mode="indeterminate")
prog.pack()
prog.start()
task()
prog.stop()
top.destroy()
t = Thread(target=show_prog)
t.start()
root = Tk()
root.geometry("300x55")
root.resizable(0, 0)
Label(text="点击测试查看效果").pack()
Button(text="测试", command=test).pack()
root.mainloop()
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
class App(Tk):
def __init__(self, geo, title):
super().__init__()
self.geometry(geo)
self.title(title)
self.btn = Button(self, text='开始任务', command=self.pbar_update)
self.btn.pack(pady=20)
self.pbar = ttk.Progressbar(self, length=400, maximum=400)
self.pbar['value'] = 0
self.pbar.pack(pady=20)
self.cid_pbar = None
def pbar_update(self):
'''每半秒钟更新一次进度条'''
print(self.pbar['value'])
self.pbar['value'] += 20
if self.pbar['value'] >= 400:
messagebox.showinfo(message="任务已完成!!")
self.pbar['value'] = 0
else:
# 没超过400 (最大值)的话,就循环更新进度
if self.cid_pbar is not None:
self.after_cancel(self.cid_pbar)
self.cid_pbar = self.after(500, self.pbar_update)
else:
self.cid_pbar = self.after(500, self.pbar_update)
if __name__ == "__main__":
app = App('500x500', '任务进度条-test')
app.mainloop()
阿奇_o 发表于 2021-8-27 23:03
对不起,上面比您快一些,我把最佳给它了,对不起
页:
[1]