以下是一个Python Tkinter程序,用于下载文件并显示进度条,下载完成后弹出提示框:文章源自爱尚资源教程网-https://www.23jcw.net/6564.html
import tkinter as tk from tkinter import ttk from tkinter import messagebox from urllib.request import urlretrieve class DownloadApp: def __init__(self, master): self.master = master self.master.title("下载进度条") self.master.geometry("300x100") self.progress = ttk.Progressbar(self.master, orient="horizontal", length=280, mode="determinate") self.progress.grid(row=0, column=0, padx=10, pady=10) self.button = tk.Button(self.master, text="下载", command=self.download) self.button.grid(row=1, column=0, padx=10, pady=10) def download(self): url = "https://www.python.org/ftp/python/3.9.5/python-3.9.5-amd64.exe" filename = "python-3.9.5-amd64.exe" urlretrieve(url, filename, self.report_hook) messagebox.showinfo("下载完成", "文件已下载完成!") def report_hook(self, blocknum, blocksize, totalsize): percent = int(blocknum * blocksize * 100 / totalsize) self.progress["value"] = percent self.master.update_idletasks() if __name__ == "__main__": root = tk.Tk() app = DownloadApp(root) root.mainloop()
在这个例子中,我们使用了Python的内置模块`tkinter.messagebox`来弹出提示框。在下载完成后,我们调用`messagebox.showinfo`方法来显示一个消息框,告诉用户文件已下载完成。文章源自爱尚资源教程网-https://www.23jcw.net/6564.html 文章源自爱尚资源教程网-https://www.23jcw.net/6564.html
相关文章
版权声明:文章图片资源来源于网络,如有侵权,请留言删除!!!