Python 本地文件選擇框


from tkinter import filedialog
import tkinter

#定義文件路徑選擇時間
def Button_command():
    # Folderpath = filedialog.askdirectory()  # 獲得選擇好的文件夾
    Filepath = filedialog.askopenfilename()  # 獲得選擇好的文件
    

    t1 = tkinter.StringVar()
    t1.set(Filepath)
    entry = tkinter.Entry(root1, textvariable=t1).place(x=80, y=15)
    print(t1.get())

if __name__ == '__main__':
    root1 = tkinter.Tk()
    root1.geometry('300x400')
    root1.wm_title('GUI')
    label0 = tkinter.Label(root1, text='文件路徑:')
    label0.place(x=10, y=10)
    t2 = tkinter.Entry(root1, width=20).place(x=80, y=15)
    btn = tkinter.Button(root1, text='...',width=2, height=1,command=Button_command).place(x=240, y=10)
root1.mainloop()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM