1.Import library
โค้ด: เลือกทั้งหมด
from tkinter import *
from tkinter import filedialog
โค้ด: เลือกทั้งหมด
def OpenFile():
name = filedialog.askopenfilenames(initialdir="",
filetypes =(("PNG Files", "*.png")("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()
โค้ด: เลือกทั้งหมด
name = filedialog.askopenfilenames(initialdir="",
filetypes =(("PNG and JPG Files", "*.png *jpg"),("All Files","*.*")),
title = "Choose a file."
)
อ้างอิง
https://www.programcreek.com/python/example/95887/tkinter.filedialog.askopenfilenames
https://stackoverflow.com/questions/44403566/add-multiple-extensions-in-one-filetypes-mac-tkinter-filedialog-askopenfilenam
https://books.google.co.th/books?id=45lUDwAAQBAJ&pg=PA86&lpg=PA86&dq=tkinter+filetype&source=bl&ots=eXh-uKEeSf&sig=ACfU3U3yVcxldoFPKOc8YZ-dwpfGltBN0A&hl=th&sa=X&ved=2ahUKEwj9gNfGlavnAhX0heYKHSudCoAQ6AEwB3oECAkQAQ#v=onepage&q=tkinter%20filetype&f=false
ศึกษาเพิ่มเติม
วีดีโอสอน Python
บทความที่น่าสนใจเกี่ยวกับ python
แชร์ความรู้เกี่ยวกับ python
การใช้งาน Python GUI (Tkinter) : variations on Hello world
การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button