Python Forum
Subprocesses not opening File Select Dialog
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocesses not opening File Select Dialog
#1
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
Reply
#2
Try to remove the two '"' in the subprocess arguments.
Reply
#3
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to view all installed software in a dialog Tyrel 6 393 Oct-09-2021, 08:11 PM
Last Post: Tyrel
  Set Text in Open Dialog Box giddyhead 0 394 May-21-2021, 06:31 PM
Last Post: giddyhead
  Terminating Subprocesses and Threads while they're calculating lvlanson 4 890 Oct-17-2020, 12:33 PM
Last Post: lvlanson
  Opening file and outputting its text content example leodavinci1990 1 740 Oct-12-2020, 05:33 AM
Last Post: buran
  File Opening Hitso 10 2,261 Jun-05-2020, 10:35 AM
Last Post: DeaD_EyE
  Test a file for a string without opening it? tester_V 2 981 Jun-03-2020, 06:40 PM
Last Post: tester_V
  How to assess elapsed time to execute a .exe file or opening a desktop application? Sudershan 2 1,103 Apr-18-2020, 01:40 PM
Last Post: buran
  Opening a file amitsinbox 6 1,478 Apr-13-2020, 11:54 AM
Last Post: amitsinbox
  Opening CSV file from SFTP server not working cluelessintern 0 1,289 Apr-08-2020, 08:10 PM
Last Post: cluelessintern
  How To Find an Opening and Closing String, Copying Open/Close/Contents to New File davidshq 1 955 Mar-03-2020, 04:47 AM
Last Post: davidshq

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020