Subprocess window won't open on Mac - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: Subprocess window won't open on Mac (/thread-32380.html) |
Subprocess window won't open on Mac - blakefindlay - Feb-05-2021 So I've been working on a rental form program for my work. Long story short I am using tkinter gui and I've set up a subprocess to open the specific rental form program from the main menu. Each .py file opens perfectly fine individually but wont open when its called from the sub-process. I get an error in terminal that says ImportError: No module named tkinter. For the record, all of my .py files that are part of this have tkinter imported. Any help is appreciated RE: Subprocess window won't open on Mac - deanhystad - Feb-06-2021 This simple example works for me, but I am using Windows instead of a mac. import tkinter as tk import subprocess proc = None def launch_proc(): global proc proc = subprocess.Popen(['python', 'junk2.py']) def kill_proc(): global proc if proc is not None: proc.terminate() proc = None root = tk.Tk() tk.Button(root, text='Launch', command=launch_proc).pack() tk.Button(root, text='Kill', command=kill_proc).pack() tk.mainloop()File junk2.py import tkinter as tk root = tk.Tk() tk.Label(root, text='2nd window').pack() tk.mainloop()Just because this works for me doesn't mean I endorse writing programs like this. Were I writing a project with multiple forms, I would probably use a notebook and make a page for each form. One application, multiple views, and a very clean way to go from one form to another. |