zoukankan      html  css  js  c++  java
  • Python_tkinter(4)_上传文件

     1.上传单个文件

    import tkinter as tk
    from tkinter import filedialog
    
    def upload_file():
        selectFile = tk.filedialog.askopenfilename()  # askopenfilename 1次上传1个;askopenfilenames1次上传多个
        entry1.insert(0, selectFile)
    
    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()

    运行结果如下

    选择文件后

    2.上传多个文件

    import tkinter as tk
    from tkinter import filedialog
    
    def upload_files():
        selectFiles = tk.filedialog.askopenfilenames(
            title='可选择1个或多个文件')  # askopenfilename 1次上传1个;askopenfilenames1次上传多个
        for selectFile in selectFiles:
            text1.insert(tk.END, selectFile + '
    ')  # 更新text中内容
            text1.update()
    
    root = tk.Tk()
    
    frm = tk.Frame(root)
    frm.grid(padx='20', pady='30')
    btn = tk.Button(frm, text='上传文件', command=upload_files)
    btn.grid(row=0, column=0, ipadx='3', ipady='3', padx='10', pady='20')
    text1 = tk.Text(frm, width='55', height='15')
    text1.grid(row=0, column=1)
    
    root.mainloop()

    运行效果: 

  • 相关阅读:
    PHP中的无限级分类
    JS中json数据格式取值实例
    PHP中类的延迟绑定
    电阻
    不能做“没事找抽型”投资者
    Delphi相关文件扩展名介绍
    三极管
    沃伦·巴菲特
    电压,电流,电阻的关系就是欧姆定律
    CnPack 使用的组件命名约定
  • 原文地址:https://www.cnblogs.com/happy-xiaoxiao/p/10493760.html
Copyright © 2011-2022 走看看