简体   繁体   中英

How can I Make System to open files when double click in Python?

I want My Audio Files to Be Opened with my Python Program. So How Can I do it?

For Example: There is a Audio File on My Desktop. And Now If I Double Click it, It Opens in The Default Viewer. But I Want it to open it in my Program.

PS I am on Mac.

You can automate double click using pyautogui or pynput modules.

from pyautogui import click
# you need to find out the value of x and y
# for that you can use pyautogui.position function
click(x, y)

You can use a inbuild module called os

here's the doc: https://docs.python.org/3/library/os.html

the anwser to your problem is

os.startfile(<path to your 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