การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button

แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
Jom07
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 514
ลงทะเบียนเมื่อ: 08/01/2018 9:56 am

การใช้งาน Python GUI (Tkinter) : การ Browse file (การค้นหาไฟล์) จากการกดปุ่ม Button

โพสต์ที่ยังไม่ได้อ่าน โดย Jom07 »

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

โค้ด: เลือกทั้งหมด

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 จะขึ้นหน้าต่างให้เราเลือกไฟล์

รูปภาพ
รูปภาพ
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 76