3

I would like to open a specific folder (not a file) in the file manager by pushing a button in a Tkinter frame. Does anyone know the function?

  • 3
    This question is a programming question (“how to interact with the UI of another program from within a Python program”) which should be asked elsewhere as it is not specific to the Raspberry Pi. – Phil B. Dec 15 '19 at 13:21
7

For asynch :

import os 
myfolder="/home/pi/Desktop"

def onMyButtonClick():
     os.system("pcmanfm \"%s\"" % myfolder)

For asynch or ̶s̶y̶n̶c̶h̶ use python subprocess Popen :

import subprocess

myfolder="/home/pi/Desktop"

def onMyButtonClick():        
    p = subprocess.Popen(["pcmanfm", "%s" % myfolder], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    p.communicate()

subprocess ref.

PCMan File Manager (PCManFM) ref.

  • 1
    Thank you very much! The first option works fine – Stan Eskin Dec 14 '19 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.