0

I am developping a GUI with tkinter and I binded this function to a button b. Once I click the button, the file is opened in notepad++ , the main problem is that I can t do anything with the GUI (no response while notepad is opened). Once I close Notepad++, I am again able to click on buttons in the GUI. In other words, this call of open_notepad doesn t come to an end. I want to have access to the GUI even if notepad is opened (open_notepad is called)

def open_notepad(file,line):
    subprocess.call([
        r"C:\Program Files\Notepad++\notepad++.exe",
        "-n",line,file
    ])
    print(line)

notepad_button = Button(root, text="open notepad")
notepad_button.bind("<Button-1>", lambda event: open_notepad(file_init, line))notepad.pack()
  • But ‘call’ and ‘run’ are designed to wait and return something when the subprocess finishes. – quamrana Jan 22 '21 at 14:00

1 Answers1

1

The call function blocks until the sub-process exits. Therefore, the GUI event loop is prevented from running. Try spawning it as a background process.

proc = subprocess.Popen(["notepad++.exe", "-n", line, file])
Keith
  • 42,110
  • 11
  • 57
  • 76