Python Forum
Subprocess window won't open on Mac
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess window won't open on Mac
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 485 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  Now if window is open or not delcencen 5 1,627 Mar-25-2023, 07:26 PM
Last Post: deanhystad
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 1,507 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [Tkinter] Open tkinter colorchooser at toplevel (so I can select/focus on either window) tabreturn 4 1,900 Jul-06-2022, 01:03 PM
Last Post: deanhystad
  Second Window can't open due to iExit function Jionni 4 2,533 Feb-29-2020, 06:06 PM
Last Post: Jionni
  tkinter window and turtle window error 1885 3 6,712 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,073 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020