โดย benzas00123 » 30/01/2020 5:46 pm
หลังจากที่เราได้ทำการศึกษา
การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Butto Browse file แบบ ทีละไฟล์มาแล้ว จาก การใช้งาน
Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button[/url] วันนี้เราจะมาลองเขียนให้สามารถ เลือกได้ทีละหลาย File กันครับ โดยใช่ Tkinter เขียนด้วยภาษา python โดยวิธีเขียนจะมีดังนี้
1.ทำการ Import library
โค้ด: เลือกทั้งหมด
from tkinter import *
from tkinter import filedialog
2.สร้างฟังก์ชั่นไว้สำหรับเรียกไฟล์
โค้ด: เลือกทั้งหมด
def OpenFile():
name = filedialog.askopenfilenames(initialdir="",
filetypes =(("Python", "*.py"),("All Files","*.*")),
title = "Choose a file."
)
print (name)
3.สร้าง หน้า Gui และปุ่ม
โค้ด: เลือกทั้งหมด
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()
รูปโปรแกรม
- Python Knowledge-1.png (5.88 KiB) Viewed 1882 times
ผลลัพธ์
- Python Knowledge-2.png (21.37 KiB) Viewed 1882 times
- Python Knowledge-3.png (6.83 KiB) Viewed 1882 times
ค่าที่แสดงออกมาจะเป็น 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
หลังจากที่เราได้ทำการศึกษา [url=https://www.mindphp.com/forums/viewtopic.php?f=144&t=45907]การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Butto[/url] [url=https://www.mindphp.com/forums/viewtopic.php?f=144&t=45907]Browse[/url] file แบบ ทีละไฟล์มาแล้ว จาก การใช้งาน [url=https://www.mindphp.com/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD/73-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3/2417-python-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]Python[/url] GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button[/url] วันนี้เราจะมาลองเขียนให้สามารถ เลือกได้ทีละหลาย File กันครับ โดยใช่ Tkinter เขียนด้วยภาษา python โดยวิธีเขียนจะมีดังนี้
1.ทำการ Import library
[code]from tkinter import *
from tkinter import filedialog [/code]
2.สร้างฟังก์ชั่นไว้สำหรับเรียกไฟล์
[code]def OpenFile():
name = filedialog.askopenfilenames(initialdir="",
filetypes =(("Python", "*.py"),("All Files","*.*")),
title = "Choose a file."
)
print (name)[/code]
3.สร้าง หน้า Gui และปุ่ม
[code]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()
[/code]
รูปโปรแกรม
[attachment=2]Python Knowledge-1.png[/attachment]
ผลลัพธ์
[attachment=1]Python Knowledge-2.png[/attachment]
[attachment=0]Python Knowledge-3.png[/attachment]
ค่าที่แสดงออกมาจะเป็น Tuple และ และจะมีค่าเป็นตำแหน่งของไฟล์ + ชื่อไฟล์
เป็นอย่างไรบ้างครับกับ ฟังก์ชั่นในวันนี้หวังว่าหลายๆคนที่กำลังศึกษาหรือกำลังทำโปรเจคที่เกี่ยวกับการอัพโหลดพวก ไฟล์ข้อมูลหรือ ไฟล์รูป หวังว่าคงจะมีประโยชน์บ้างไม่มากก็น้อยนะครับ
อ้างอิง
https://stackoverflow.com/questions/16790328/open-multiple-filenames-in-tkinter-and-add-the-filesnames-to-a-list
https://gist.github.com/vperezma/85202b860ee359c23d37ab5331121fc6
[url]https://www.mindphp.com/forums/viewtopic.php?f=144&t=45907[/url]
ศึกษาเพิ่มเติม
[url=https://www.mindphp.com/vdo-tutorial-python.html]วีดีโอสอน python[/url]
[url=https://www.mindphp.com/forums/viewforum.php?f=144]python แชร์ความรู้[/url]
[url=https://www.mindphp.com/developer/tips-python.html]บทความที่มีประโยชน์เกี่ยวกับ python[/url]
[url=https://www.mindphp.com/forums/viewtopic.php?f=144&t=45907]การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button[/url]