snipplets.dev/code/Python/Tk/select-file-folder.py

27 lines
499 B
Python
Raw Normal View History

2023-06-05 21:55:36 +03:00
from tkinter import filedialog
from tkinter import *
root = Tk()
root.withdraw()
def select_file():
file_selected = filedialog.askopenfilename(
title='Open a file',
initialdir='/',
filetypes=(
('Text files', '*.txt'),
('All files', '*.*')
)
)
print(file_selected)
def select_folder():
folder_selected = filedialog.askdirectory()
print(folder_selected)
if __name__ == '__main__':
select_file()
select_folder()