Blog/content/posts/2023/python/tk-file-folder-select-dialog.md
2023-06-05 21:52:39 +03:00

707 B

title date draft tags
🗂️ Диалог выбора директории/файлов в Tk на Python 2023-06-05T21:47:33+03:00 false
tk
python
tips

📄 Выбор файла

from tkinter import filedialog
from tkinter import *

root = Tk()
root.withdraw()

file_selected = filedialog.askopenfilename(
    title='Open a file',
    initialdir='/',
    filetypes=(
        ('Text files', '*.txt'),
        ('All files', '*.*')
    )
)

print(file_selected)

📁 Выбор директории

from tkinter import filedialog
from tkinter import *

root = Tk()
root.withdraw()

folder_selected = filedialog.askdirectory()

print(folder_selected)