Subprocesses not opening File Select Dialog - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Subprocesses not opening File Select Dialog (/thread-32630.html) |
Subprocesses not opening File Select Dialog - teut - Feb-22-2021 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 RE: Subprocesses not opening File Select Dialog - Gribouillis - Feb-22-2021 Try to remove the two '"' in the subprocess arguments.
RE: Subprocesses not opening File Select Dialog - teut - Feb-22-2021 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() |