[Tutor] Opening a Qt .py file from within another python app
krush1954 at yahoo.com
Thu Mar 22 10:57:56 CET 2012
On 22/03/12 03:47, ken brockman wrote:
>> 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.
>My guess is that there is an if __name__... clause
>at the bottom with some code that doesn't get
>executed when you import it. That clause has some
>initialisation code that starts the main window up.
>Try opening the file in an editor and seeing what is
>happening there. You will either need to move that
>into a function then call the function after importing,
>or replicate it in your top level file.
>Having said that the os.system technique should have worked regardless, but it won't let you do any more integration.
>-- Alan G
Thanks much Alan for you time and input.
I had managed to get it to run, after reading that the if __name__=__main__ at the bottom of the Qt file is what makes it fire up if run directly.
I had figured that if I were to copy those last few lines after that statement from the bottom of the Qt file into my main file, that it may just work. And, after affixing the name of the Qt file, which i had import into my main app, to the beginning of one or two calls from that bit, it did run. Only problem was, that it was all it did. It open and displayed the window, but the rest of the file didn't run. I'm guessing it may have to do with something in the body of those few lines i had copied. Either that or something in the qt file its self, waiting for a connection or some such. Since i am fairly new to both python and Qt and hardly up to speed in either I will just have to prod along and try my limited best to work it out..
Curious how the os.system technique hadn't worked though? From what you said it should have done the trick.
Oh well, thank you once again for your help.
Have a good day.
PS Another odd bit, was on the python docs page. It had said that using import File_name, without the .py would import it, but not run it. Seems a glaring oversight not to have mentioned, what would have made it run. Sure would have made my life a lot easier anyway.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor