การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button
Posted: 27/02/2018 4:16 pm
การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button เป็นการสร้างปุ่มให้ Browse หาไฟล์ได้ เมื่อกดปุ่ม เช่น
ตัวอย่าง
ผลรัน

เมื่อกดปุ่ม Browse จะขึ้นหน้าต่างให้เราเลือกไฟล์

ตัวอย่าง
Code: Select all
from tkinter import filedialog
from tkinter import *
root = Tk()
def selection():
root.filename = filedialog.askopenfile(initialdir = "/",title = "Select file",filetypes = (("files","*.exe"),("all files","*.*")))
print(root.filename)
Button(text = ' Browse ' ,bd = 3 ,font = ('',10),padx=5,pady=5, command=selection).grid(row=1,column=1)
root.mainloop()
เมื่อกดปุ่ม Browse จะขึ้นหน้าต่างให้เราเลือกไฟล์