I have a test environment in python. it is executed by the following command on the command prompt.
1) First i have to go to the dir where the .py file is
2) then i simply execute python filename.py and the GUI appears
Now i have to create a script which could open the GUI...i.e execute the command "python filename.py" from inside itself.. I tried the "system" command inside my script but the GUI did not appear.i.e i tried
system("python filename.py") but nothing appeared on the screen
Plz help.
17 176636
Forgive me if this seems too elementary, but without full code or output to examine I am stretching, did you import os? For example if test.py contains - import os
-
os.system('python hello.py')
and hello.py just prints hello, then - C:\tmp>python test.py
-
hello
should do what you are asking unless there are other path or module issues. When you say the GUI doesn't appear, does anything happen? Are there errors?
The python "Process Management" docs may be of help.
Forgive me if this seems too elementary, but without full code or output to examine I am stretching, did you import os? For example if test.py contains - import os
-
os.system('python hello.py')
and hello.py just prints hello, then - C:\tmp>python test.py
-
hello
should do what you are asking unless there are other path or module issues. When you say the GUI doesn't appear, does anything happen? Are there errors?
The python "Process Management" docs may be of help.
to run another python script from your script: -
import myscript
-
myscript.somefunc()
-
just like importing the standard modules.
Forgive me if this seems too elementary, but without full code or output to examine I am stretching, did you import os? For example if test.py contains - import os
-
os.system('python hello.py')
and hello.py just prints hello, then - C:\tmp>python test.py
-
hello
should do what you are asking unless there are other path or module issues. When you say the GUI doesn't appear, does anything happen? Are there errors?
The python "Process Management" docs may be of help.
Thanx for the prompt reply...but as u have asked...i had already imported os and executedthe following command from my python script:
os.system("python filename.py")
no error message was flagged and the command was successfully executed leading to the command prompt again but the GUI did not appear.
What could be the probable reason.??
Initially i used to run the GUI by simply typing:
python filename.py
Thanx for the prompt reply...but as u have asked...i had already imported os and executedthe following command from my python script:
os.system("python filename.py")
no error message was flagged and the command was successfully executed leading to the command prompt again but the GUI did not appear.
What could be the probable reason.??
Initially i used to run the GUI by simply typing:
python filename.py
Is your GUI Tkinter, or some other toolkit?
Is your GUI Tkinter, or some other toolkit?
i don't know about the tool kit...
it was made for some testing puposes. i load my test files into that and press a runtest button.
I have a test environment in python. it is executed by the following command on the command prompt.
1) First i have to go to the dir where the .py file is
2) then i simply execute python filename.py and the GUI appears
Now i have to create a script which could open the GUI...i.e execute the command "python filename.py" from inside itself.. I tried the "system" command inside my script but the GUI did not appear.i.e i tried
system("python filename.py") but nothing appeared on the screen
Plz help.
By any chance, do you give command line arguments when you call python manually? If so, try - system("python filename.py arg1 arg2")
By any chance, do you give command line arguments when you call python manually? If so, try - system("python filename.py arg1 arg2")
no there are no command line arguments . i just run python filename.py from the command prompt while running the GUI manually.
no there are no command line arguments . i just run python filename.py from the command prompt while running the GUI manually.
personally, i would not recommend this method of calling a python script from anther. The "cleaner" approach is to import it.
for example , in script called myscriptA.py, you have -
def displayGUI():
-
print "I am from myscriptA.py in functoin displayGUI"
-
return
-
then in myscriptB.py, you can call your GUI display function like this -
import myscriptA ##or from myscriptA import displayGUI
-
myscriptA.displayGUI()
-
Hi, I'm just trying to follow along and had a question.....is it that your script will run in a dos window but what you want is for it to run on IDLE?
ex: -
>>> for i in range(5):
-
print i
-
-
-
1
-
2
-
3
-
4
-
>>>
-
-
so if your saved that script as loop.py: -
for i in range(5):
-
print i
-
and then wrote: -
import os,sys
-
os.system(r"C:\python25\loop.py")
-
then saved it as testrun.py. If you execute testrun.py, it runs the loop in a dos window but you want it to execute and print out to IDLE instead? Is that it, or am I on the wrong track in trying follow?
Hi...
i guess my question is not clear...
i have a test environment. The GUI for the environment appears when on the DOS window i type the following command:
python filename.py
A window appears where in i can load my tests and then click on the tab in the GUI which says run tests.
Now the situation is...i am supposed to do some initial processing before loading the tests.....which includes opening a csv file thru a python script,reading a particular row of the csv file,gettings inputs from there and then loading the test files in the GUI.
so i am supposed to open the GUI after all this processing...from the python script and no more by typing command on the DOS window.
i tried to execute the same command : python filename.py from the python script like this:
import os
os.system("python filename.py")
but it did not wrk...
what shud i do
Hi...
i guess my question is not clear...
i have a test environment. The GUI for the environment appears when on the DOS window i type the following command:
python filename.py
A window appears where in i can load my tests and then click on the tab in the GUI which says run tests.
Now the situation is...i am supposed to do some initial processing before loading the tests.....which includes opening a csv file thru a python script,reading a particular row of the csv file,gettings inputs from there and then loading the test files in the GUI.
so i am supposed to open the GUI after all this processing...from the python script and no more by typing command on the DOS window.
i tried to execute the same command : python filename.py from the python script like this:
import os
os.system("python filename.py")
but it did not wrk...
what shud i do
Here is a basic Tkinter GUI probram that doesn't do anything except put a button in a frame: - # TkButtonFrame.py'
-
from Tkinter import *
-
-
class TestFrame(Frame):
-
def __init__(self, parent, *args, **kwargs):
-
Frame.__init__(self, parent)
-
self.testButton = Button(text='Run Test')
-
self.testButton.pack()
-
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
testFrame = TestFrame(root)
-
testFrame.pack()
-
root.mainloop()
-
It does have the __main__ "guard" in it that I thought might cause the problem.
Here is the command module: - # rungui.py
-
import os
-
os.system('python TkButtonFrame.py')
-
If you run the command rungui.py, the GUI will appear.
If it looks like your test program, then the toolkit used to make it is Tkinter.
If you put these modules into your test environment and they don't work, then something (most likely PYTHONPATH) is not set up correctly.
Here is a basic Tkinter GUI probram that doesn't do anything except put a button in a frame: - # TkButtonFrame.py'
-
from Tkinter import *
-
-
class TestFrame(Frame):
-
def __init__(self, parent, *args, **kwargs):
-
Frame.__init__(self, parent)
-
self.testButton = Button(text='Run Test')
-
self.testButton.pack()
-
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
testFrame = TestFrame(root)
-
testFrame.pack()
-
root.mainloop()
-
It does have the __main__ "guard" in it that I thought might cause the problem.
Here is the command module: - # rungui.py
-
import os
-
os.system('python TkButtonFrame.py')
-
If you run the command rungui.py, the GUI will appear.
If it looks like your test program, then the toolkit used to make it is Tkinter.
If you put these modules into your test environment and they don't work, then something (most likely PYTHONPATH) is not set up correctly.
It's important to note that
WILL NOT WORK because of the if __name__ == "__main__": guard.
Here is a basic Tkinter GUI probram that doesn't do anything except put a button in a frame: - # TkButtonFrame.py'
-
from Tkinter import *
-
-
class TestFrame(Frame):
-
def __init__(self, parent, *args, **kwargs):
-
Frame.__init__(self, parent)
-
self.testButton = Button(text='Run Test')
-
self.testButton.pack()
-
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
testFrame = TestFrame(root)
-
testFrame.pack()
-
root.mainloop()
-
It does have the __main__ "guard" in it that I thought might cause the problem.
Here is the command module: - # rungui.py
-
import os
-
os.system('python TkButtonFrame.py')
-
If you run the command rungui.py, the GUI will appear.
If it looks like your test program, then the toolkit used to make it is Tkinter.
If you put these modules into your test environment and they don't work, then something (most likely PYTHONPATH) is not set up correctly.
The __main__ of my test file looks like this: -
# if running standalone
-
if __name__ == "__main__":
-
app = MyApp(0) # Create an instance of the application class
-
app.MainLoop() # Tell it to start processing events
-
-
# End of Program
The __main__ of my test file looks like this: -
# if running standalone
-
if __name__ == "__main__":
-
app = MyApp(0) # Create an instance of the application class
-
app.MainLoop() # Tell it to start processing events
-
-
# End of Program
I've added CODE tags to your post. Please read "REPLY GUIDELINES" to learn how to do this.
So how is the class MyApp defined?
I've added CODE tags to your post. Please read "REPLY GUIDELINES" to learn how to do this.
So how is the class MyApp defined?
Class MyaApp is as follows: -
-
class MyApp(wx.App):
-
# wxWindows calls this method to initialize the application
-
def OnInit(self, operator=None):
-
-
# Create an instance of our customized Frame class
-
frame = MyFrame(None, -1, "PetShopTest")
-
frame.Show(1)
-
# and let wxWindows know that is our main window...
-
self.SetTopWindow(frame)
-
-
# we need to return a success flag (to keep wxWindows happy)...
-
return 1
-
-
Class MyaApp is as follows: -
-
class MyApp(wx.App):
-
# wxWindows calls this method to initialize the application
-
def OnInit(self, operator=None):
-
-
# Create an instance of our customized Frame class
-
frame = MyFrame(None, -1, "PetShopTest")
-
frame.Show(1)
-
# and let wxWindows know that is our main window...
-
self.SetTopWindow(frame)
-
-
# we need to return a success flag (to keep wxWindows happy)...
-
return 1
-
-
Awesome! Your GUI Toolkit is wxPython. It's the best in my opinion.
Since this should work, there can be only one reson why it doesn't:
Python doesn't know how to find your program (you've been calling it "filename.py). You probably need to specify the entire path in the command. Use raw strings for path names on windows: - r"D:\Python24\Lib\filename.py"
Or you can add the path to the environment variable called PYTHONPATH in the operating system. Or you can put path into a file with any name (say) testpath.pth into the D:\Python24\Lib\site-packages (on my system) directory. The .pth extention tells python to add whaterver is in that file to sys.path.
bro use 'py' in cmd instead of 'python'.if it works or you may need to setup path.
its just an assumption. :))
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Amir |
last post by:
Can one PHP script execute another PHP script?
|
by: Irmen de Jong |
last post by:
QOTW: "Confronting the Martellibot is like flirting with an encyclopedia,
I'd rather not do it myself, but I respect those who do, because it
produces knowledge." -- Anton...
|
by: Steve |
last post by:
Hi,
I've written a small cgi python script that collects feedback from a
webform. I need to pass the values to another python script.. how do I
do this? Is this even possible? Thanks
Steve
|
by: Paul Cochrane |
last post by:
Hi all,
I've got an application that I'm writing that autogenerates python code
which I then execute with exec(). I know that this is not the best way to
run things, and I'm not 100% sure as to...
|
by: Eric_Dexter |
last post by:
I was looking for a simple way to load a simple python program from
another python program.
I tried
os.system(cabel)
The file name is cabel.py a csound instrument editor..
The error I am...
|
by: KraftDiner |
last post by:
I have a class that is defined in a file called MyClass.py
How do I use that class in another python script..
import MyClass ? (Does it need to be in a specific location?)
|
by: maya |
last post by:
hi,
I keep getting this error, "can't execute code from a freed script" when
I go to another page (i.e., upon UNLOAD..)
this error occurs only in IE, not FF (what a surprise.....;)
what is...
|
by: Alexandru Mosoi |
last post by:
how do I execute another python script under a different process? I
want the script to be run using the same interpretoer as the one
running current script. I tried using os.execlp but I don't know...
|
by: gintrado |
last post by:
I am very new to Python I'm trying to run a python script from within another python script. I can run the script from a unix command line by typing: nohup python script.py password >...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |