Python Forum

Full Version: Subprocesses not opening File Select Dialog
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello ,
I am trying to run a command which should open up a File Select Windows widget in Kivy. Kivy has the non-native FileChooser class which is not user friendly in my perspective. My plan is to use a subprocess call to run a powershell script which would open a File Select Dialog.

class UserInfoWidget(BoxLayout):
    def browse_file(self):
        p = subprocess.Popen(["powershell.exe",
                              '"' + os.path.join(os.getcwd(), "filebrowser.ps1")+'"'],
                             stdout=sys.stdout)
        p.communicate()
Clicking the button once the kivy gui is launched gives the default statements in the shell and then when button is clicked gives
C:\Users\Dell\OneDrive\Desktop\New folder\filebrowser.ps1 in the shell.Why is the File Dialog not opening?
It is opening when I run powershell.exe ./filebrowser.ps1 in windows powershell or command prompt.
Img1- https://ibb.co/1G5SKMF
Img2 - https://ibb.co/bR44JqK
Try to remove the two '"' in the subprocess arguments.
I fixed it now. And those " " are important because of file paths like "C:/Users/New Folder/...". Observe the space please. I copied this code from StackOverflow

class UserInfoWidget(BoxLayout):
    def browse_file(self):
        
        co_initialize = ctypes.windll.ole32.CoInitialize
        co_initialize(None)
        import clr
        clr.AddReference('System.Windows.Forms')
        from System.Windows.Forms import OpenFileDialog

        file_dialog = OpenFileDialog()
        print(dir(file_dialog))
        file_dialog.Filter = "Excel files|*.xls;*.xlsx"
        ret = file_dialog.ShowDialog()
        # if ret != 1:
        #     print("Cancelled")
        #     sys.exit()