Spawning separate processes
Under some circumstances, it is not possible to implement the desired functionality for your application just by using threads. For instance, you might want to call a separate program that could be written in a different language.
In this case, we also need to use the subprocess
module to invoke the target program from our Python process.
Getting ready
The following example performs a ping to an indicated DNS or IP address:

How to do it...
As usual, we define a customAsyncAction
method, but, in this case, we call subprocess.run()
with the value set in the Entry widget.
This function starts a separate subprocess that, unlike threads, uses a separate memory space. This means that in order to get the result of the ping
command, we must pipe the result printed to the standard output and read it in our Python program:
import threading import subprocess import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() self.entry = tk.Entry...