python 文件上传

2023-10-13 17:07:31 浏览数 (1)

代码语言:javascript复制
```python
import tkinter as tk
from tkinter import filedialog


def upload_file():
    selectFile = tk.filedialog.askopenfilename()
    entry1.insert(0, selectFile)
    print('上传的文件为: {}'.format(entry1.get()))


root = tk.Tk()

frm = tk.Frame(root)
frm.grid(padx='20', pady='30')
btn = tk.Button(frm, text='上传文件', command=upload_file)
btn.grid(row=0, column=0, ipadx='3', ipady='3', padx='10', pady='20')
entry1 = tk.Entry(frm, width='40')
entry1.grid(row=0, column=1)

root.mainloop()

0 人点赞