当前位置: 首页 > news >正文

tkinter 实现选择文件夹或者多个文件

import tkinter as tk
from tkinter import filedialog
def select_file():
    # 单个文件选择
    selected_file_path = filedialog.askopenfilename()  # 使用askopenfilename函数选择单个文件
    select_path.set(selected_file_path)
def select_files():
    # 多个文件选择
    selected_files_path = filedialog.askopenfilenames()  # askopenfilenames函数选择多个文件
    select_path.set('\n'.join(selected_files_path))  # 多个文件的路径用换行符隔开
def select_folder():
    # 文件夹选择
    selected_folder = filedialog.askdirectory()  # 使用askdirectory函数选择文件夹
    select_path.set(selected_folder)

root = tk.Tk()
root.title("选择文件或文件夹,得到路径")
# 初始化Entry控件的textvariable属性值
select_path = tk.StringVar()
# 布局控件
tk.Label(root, text="文件路径:").grid(column=0, row=0, rowspan=3)
tk.Entry(root, textvariable = select_path).grid(column=1, row=0, rowspan=3)
tk.Button(root, text="选择单个文件", command=select_file).grid(row=0, column=2)
tk.Button(root, text="选择多个文件", command=select_files).grid(row=1, column=2)
tk.Button(root, text="选择文件夹", command=select_folder).grid(row=2, column=2)
root.mainloop()

http://www.lryc.cn/news/1978.html

相关文章:

  • 深圳活动会议媒体邀约,电视台,网媒媒体资源
  • JDBC与Druid连接池
  • java易错题锦集二
  • 11.hadoop系列之MapReduce框架原理之InputFormat数据输入
  • LoadRunner
  • 笔试题-2023-芯原-数字前端设计or验证【纯净题目版】
  • 【软件测试】资深测试工程师说:你真的能做好bug分析吗?
  • NLP模型检查英语语法错误
  • Echarts的Category轴滑动
  • 04 react css上下浮动动画效果
  • 关于线程池
  • 【GPLT 二阶题目集】L2-004 这是二叉搜索树吗?
  • Python Numpy基础教程
  • 常见HTTP请求错误码大全
  • 重保期间如何「快速」构建内容安全治理体系?
  • 用Qt开发的ffmpeg流媒体播放器,支持截图、录像,支持音视频播放,支持本地文件播放、网络流播放
  • 第七节 平台设备驱动
  • 代理模式详解
  • 根据报告20%的白领在一年内做过副业,你有做副业吗?
  • 第二十三周周报
  • 2023年Q1业绩增长背后,迪士尼亟待扭转流媒体亏损困局
  • LKWA靶场通关和源码分析
  • logcpp demo
  • 平价款的血糖血压监测工具,用它养成健康生活习惯,dido F50S Pro上手
  • 算法训练营 day42 动态规划 理论基础 斐波那契数 爬楼梯 使用最小花费爬楼梯
  • MySQL8 创建用户,设置修改密码,授权
  • MySQL —— 内置函数
  • Mybatis框架(全部基础知识)
  • pixhawk2.4.8使用调试记录—APM固件
  • 终于进了字节,记录一下我作为一名测试员磕磕碰碰的三个月找工作经历...