[Tutor] opening a Qt .py file from within another python app.

ken brockman krush1954 at yahoo.com
Thu Mar 22 04:47:04 CET 2012

Evening all;

I am trying to import a Python QT file, that had been generated from a ui file into another python app.
I have imported it, without generating an error, but the Qt window isn't opening. I have spent the afternoon googling the issue, have found numerous articles, but none that have seemed to work for me. 
I have tried:  import file, from file import *, and a slew of other suggested ways to get it to run, all to no avail.

I have tried to call the Class and other Def functions from the Qt file, up to and including __main__, but no good.
I have spend well over an hour perusing the Python on line Doc's, but If i had stumbled upon the answer I guess I am too slow to have recognized it.

I had come across this great piece on Stack overflow:

There are more than a few ways. I'll list them in order of inverted preference (i.e., best first, worst last):
    1. Treat it like a module: import file. This is good because it's secure, fast, and maintainable. Code gets reused as it's supposed to be done. Most Python libraries run using multiple methods stretched over lots of files. Highly recommended. Note that if your file is called file.py, your import should not include the .py extension at the end.
    2. The infamous (and unsafe) exec command: execfile('file.py'). Insecure, hacky, usually the wrong answer. Avoid where possible.
    3. Spawn a shell process: os.system('python file.py'). Use when desperate.

None of which had gotten the Qt window to open. Yet when I run it directly, on it's own, it open's and the Qt window is displayed.

I am hoping it is a relatively simply Task to accomplish, but beyond the stunted abilities of my limited knowledge.

At this point I am simply trying to get the Qt window to open from the second python app. After which I have a steep hill to climb to try to connect the input from the one app to the signals of the other, but that is for another day.

Any and all help, would truly be appreciated.

python3.2, Linux Ubuntu 11.10

Thank you

More information about the Tutor mailing list