1.ทำการ Import library
โค้ด: เลือกทั้งหมด
from tkinter import *
from tkinter import filedialog
โค้ด: เลือกทั้งหมด
def OpenFile():
name = filedialog.askopenfilenames(initialdir="",
filetypes =(("Python", "*.py"),("All Files","*.*")),
title = "Choose a file."
)
print (name)
โค้ด: เลือกทั้งหมด
root = Tk()
root.geometry('200x200')
root.title("Test")
btn = Button ( root, text='Upload', command=lambda: OpenFile() , font= 10 )
btn.place(x = 50 , y= 100)
root.mainloop()
รูปโปรแกรม ผลลัพธ์
ค่าที่แสดงออกมาจะเป็น Tuple และ และจะมีค่าเป็นตำแหน่งของไฟล์ + ชื่อไฟล์
เป็นอย่างไรบ้างครับกับ ฟังก์ชั่นในวันนี้หวังว่าหลายๆคนที่กำลังศึกษาหรือกำลังทำโปรเจคที่เกี่ยวกับการอัพโหลดพวก ไฟล์ข้อมูลหรือ ไฟล์รูป หวังว่าคงจะมีประโยชน์บ้างไม่มากก็น้อยนะครับ
อ้างอิง
https://stackoverflow.com/questions/16790328/open-multiple-filenames-in-tkinter-and-add-the-filesnames-to-a-list
https://gist.github.com/vperezma/85202b860ee359c23d37ab5331121fc6
viewtopic.php?f=144&t=45907
ศึกษาเพิ่มเติม
วีดีโอสอน python
python แชร์ความรู้
บทความที่มีประโยชน์เกี่ยวกับ python
การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button