Launching another pyqt program from a currently running one

2k views Asked by At

I have two pyqt programs. Both should be available to run by themselves, but I need to run one of them from the other. The one that will only run manually is called foo and the second one (the one I want to call from foo) is called bar. I tried to follow this example and I get the new window, but with an error

AttributeError: 'bar' object has no attribute 'exec_'

I guess I could create it, but I don't know what to put in it. So how do I make another window pop by clicking a button in the first window?

Bonus points for somebody who can make the original window inactive.

Here is how my function look right now:

barMaker = bar(self)
bar.exec_()

Unimaginative, I know.

2

There are 2 answers

0
derricw On BEST ANSWER

Do you want to just call the second gui program using

new_gui = subprocess.Popen("python "+path)

?

You can then disable your first GUI or do whatever you want with it. The new GUI is running in a separate process.

0
amoodie On

@ballsatballsdotballs answer did not work for me, but was very close. Referring to the docs (same for Python2 and Python3) states:

subprocess.Popen(args, ...)

args should be a sequence of program arguments or else a single string. By default, the program to execute is the first item in args if args is a sequence. If args is a string, the interpretation is platform-dependent and described below.

I'm not sure if this has changed only since the original answer was posted (>4 yrs old), but for completeness, the following Popen construction worked for me:

new_gui = subprocess.Popen(["python", path])

One could also substitute "python3" if desired.