how can you run two parallel scripts from tkinter?

I think this will do close to what you want. It uses subprocess.Popen() instead of os.system() to run the other script and rerun the pop-up which doesn’t block execution while waiting for them to complete, so they can now execute concurrently.

I also added a Quit button to get out of the loop.

import subprocess
import sys
from tkinter import *
import tkinter as tk

root = Tk()

def sample_function():
    command = f'"{sys.executable}" ""'
    subprocess.Popen(command)  # Run other script - doesn't wait for it to finish.
    root.quit()  # Make mainloop() return.

tk.Button(text='Run sample_function', command=sample_function).pack(fill=tk.X)
tk.Button(text='Quit', command=lambda: sys.exit(0)).pack(fill=tk.X)
print('mainloop() returned')

print('restarting this script')
command = f'"{sys.executable}" "{__file__}"'

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top