Webimport tkinter as tk from tkinter import filedialog import pathlib root = tk.Tk () ask = filedialog.askopenfilename (title="Select a directory", filetypes = [ ("log",".log"), ("All Files",".*")]) print (f"User selected Directory: {pathlib.Path (ask).resolve ().parent}") root.destroy () Share Improve this answer Follow answered Jun 29, 2024 at 0:46 WebDec 22, 2013 · from tkFileDialog import askdirectory directory= askdirectory () Then in the code: import tkinter import tkinter.filedialog import getpass from tkFileDialog import askdirectory # Need this for the `os.path.split` function import os gui = tkinter.Tk () user = getpass.getuser () def click (): directory= askdirectory () print (directory) button ...
File Explorer in Python using Tkinter - GeeksforGeeks
WebTkinter是Python标准库中的一个模块,它提供了一组工具和组件,可以用于创建各种类型的GUI应用程序。 使用Tkinter,开发人员可以创建按钮、标签、文本框、滚动条、菜单等各种控件,并将它们组合在一起以创建完整的GUI应用程序。 WebMar 25, 2016 · While their is no built in way to really do this in tkinter, you could ask the user to select a file using tkinter.askopenfilename () and then use os.path.dirname () on the file selected to get the directory the file was selected from, effectively returning both a file and also a directory, all from the same dialog. – R. Kap Mar 25, 2016 at 17:07 maple overseas
Python 从tkinter列表框中跳出_Python_Tkinter_Escaping_Break
WebMar 25, 2024 · The askdirectory () method includes a dialog box that only allows directory and return directory path that the user selects. Using the askdirectory () method, first … Web1 day ago · The tkinter.filedialog module provides classes and factory functions for creating file/directory selection windows. Native Load/Save Dialogs¶ The following classes and … maple oven roasted carrots