Python3 Tkinter选择路径功能的实现方法

作者:Clew123 时间:2022-03-12 19:39:28 

效果基于Python3。

在自己写小工具的时候因为这个功能纠结了一会儿,这里写个小例子,供有需要的参考。

小例子,就是点击按钮打开路径选择窗口,选择后把值传给Entry输出。

效果预览

这是选择前:

Python3 Tkinter选择路径功能的实现方法

选择:

Python3 Tkinter选择路径功能的实现方法

选择后:

Python3 Tkinter选择路径功能的实现方法

代码

很基础的写法。


from tkinter import *
from tkinter.filedialog import askdirectory

def selectPath():
 path_ = askdirectory()
 path.set(path_)

root = Tk()
path = StringVar()

Label(root,text = "目标路径:").grid(row = 0, column = 0)
Entry(root, textvariable = path).grid(row = 0, column = 1)
Button(root, text = "路径选择", command = selectPath).grid(row = 0, column = 2)

root.mainloop()

注意事项

1.注意import模块时的写法。

2.askdirectory()方法是返回文件夹路径不是文件路径。

来源:https://blog.csdn.net/zjiang1994/article/details/53513377

标签:Python3,Tkinter,路径
0
投稿

猜你喜欢

  • Python提取频域特征知识点浅析

    2021-10-31 08:01:31
  • python快排算法详解

    2023-08-24 04:17:08
  • python爬虫框架talonspider简单介绍

    2021-05-14 06:27:01
  • python实现12306登录并保存cookie的方法示例

    2021-08-05 18:37:55
  • python3.6.3安装图文教程 TensorFlow安装配置方法

    2021-06-25 19:20:42
  • Python3中PyQt5简单实现文件打开及保存

    2023-10-17 21:45:52
  • asp 实现的冒泡排序程序

    2011-03-25 11:13:00
  • oracle 发送邮件 实现方法

    2009-06-10 17:49:00
  • Python中的异常处理相关语句基础学习笔记

    2021-10-18 00:54:50
  • Yii2 rbac权限控制之菜单menu实例教程

    2023-11-14 10:41:19
  • Python面向对象程序设计类变量与成员变量、类方法与成员方法用法分析

    2022-08-11 15:43:43
  • ASP.NET技巧:同时对多个文件进行大量写操作对性能优化

    2023-07-08 12:22:37
  • 简单了解python中的与或非运算

    2021-03-20 01:45:02
  • js和jquery判断数据类型的4种方法总结

    2023-08-25 08:49:18
  • PHP+JS实现文件分块上传的示例代码

    2023-06-12 00:04:07
  • Python不使用int()函数把字符串转换为数字的方法

    2022-04-22 02:32:33
  • Python基础语法之变量与数据类型详解

    2022-06-21 17:52:36
  • Python编程OpenCV和Numpy图像处理库实现图片去水印

    2023-10-10 15:12:44
  • 微信小程序与php 实现微信支付的简单实例

    2023-11-14 15:22:07
  • 对python中数组的del,remove,pop区别详解

    2021-01-23 09:22:31
  • asp之家 网络编程 m.aspxhome.com