I am trying to open a pdf file (using default pdf reader) from a Python script in which user chooses file from GUI. However, it takes too long to open the file after GUI.
- Python: 3.8.5
- PySimpleGUI: 4.28.0, Tkinter Port
import time
import os
import subprocess
import PySimpleGUI as sg
def without_gui_input():
return input("File: ")
def with_gui_input():
abs_path = sg.popup_get_file("Please select a file", initial_folder=".")
return os.path.relpath(abs_path)
file_path = with_gui_input() # without_gui_input()
start = time.time()
subprocess.call([file_path], shell=True)
end = time.time()
print(f"Took {end-start} seconds.")
- Without GUI: 0.4 second
- With GUI: 15.4 seconds
I could not locate the problem. I thought maybe GUI closing operation takes long but I tried to get input from a window (not popup) that is not closed after it gets input but results were the same. How can I speed up this process?
Note: I need to use call() instead of Popen() to ensure that the file is opened.
Edit: I can use Popen().communicate() instead of call() but results are the same. Both are blocking operations.