May-01-2024, 05:20 PM
(This post was last modified: May-01-2024, 05:20 PM by deanhystad.)
When excel executes a Python script, it waits for the script to complete. Your script doesn't complete until the window is closed. This blocks excel from running. There are multiple ways to solve this problem. but the easiest might be to run the window script as a subprocess.
This is my window file (window.py)
This is a python script that runs window.py as a subprocess.
You'll need to use absolute paths for python.exe and window.py.
This is my window file (window.py)
import tkinter as tk root = tk.Tk() tk.Button(root, text="Close", command=root.destroy).pack(padx=100, pady=100) root.mainloop()I can do that by running the window as a subprocess.
This is a python script that runs window.py as a subprocess.
import subprocess subprocess.Popen(["python", "window.py"]) print("I am done")Your spreadsheet calls the launch script. The lauch script starts a process to run the window.py script. Because the launch script uses Popen withou a wait(), it doesn't wait for the window to close, and doesn't block the spreadsheet.
You'll need to use absolute paths for python.exe and window.py.