python+tkinter下载
时间: 2024-01-20 16:16:58 浏览: 199
python+tkinter, gui, 计算器实现
以下是一个使用Python和tkinter库进行文件下载的简单示例:
```python
import tkinter as tk
from tkinter import filedialog
import urllib.request
def download_file():
url = entry.get()
save_path = filedialog.asksaveasfilename(defaultextension=".txt")
urllib.request.urlretrieve(url, save_path)
label.config(text="文件下载完成!")
# 创建窗口
window = tk.Tk()
window.title("文件下载")
window.geometry("300x150")
# 创建标签和输入框
label = tk.Label(window, text="请输入文件的URL地址:")
label.pack()
entry = tk.Entry(window)
entry.pack()
# 创建下载按钮
button = tk.Button(window, text="下载文件", command=download_file)
button.pack()
# 运行窗口
window.mainloop()
```
阅读全文