简体   繁体   中英

How to open File Explorer via python

Alright. I play the game FRHD . I and a friend have a picture-to-track script. Right now, in order to select a file, I have to edit the actual script and type in my file name. I know that I can use an input to get the filename through the CLI, but I want to know if there is a way to open the File Explorer and select a certain file type there. Right now I am using this code:

from tkinter import Tk
from tkinter.filedialog import askopenfilename

Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
print(filename)

What I want to know is if there is any way to only show.jpg files. Thanks, and as always, any help is greatly appreciated!

- ThePurpleBuccaneer

import subprocess
subprocess.Popen(r'explorer /select,"C:\path\of\folder\file"')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM