ফাইল ডায়লগ থেকে অ্যাবসোলিউট পাথ বের করা
filedialog.askopenfile() দিয়ে ফাইল সিলেক্ট করুন এবং os.path.abspath(file.name) দিয়ে পূর্ণ পাথ পান।
উদাহরণ
from tkinter import *
from tkinter import ttk, filedialog
from tkinter.filedialog import askopenfile
import os
win = Tk()
win.geometry("700x350")
def open_file():
file = filedialog.askopenfile(mode='r', filetypes=[('Python Files', '*.py')])
if file:
filepath = os.path.abspath(file.name)
Label(win, text="The File is located at : " + str(filepath), font=('Aerial 11')).pack()
Label(win, text="Click the Button to browse the Files", font=('Georgia 13')).pack(pady=10)
ttk.Button(win, text="Browse", command=open_file).pack(pady=20)
win.mainloop()
আউটপুট
"Browse" বাটন চাপলে ফাইল এক্সপ্লোরার খুলবে। পাইথন ফাইল সিলেক্ট করলে তার পূর্ণ পাথ লেবেলে দেখাবে।