Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links



Python script starts only from console

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-01-2010
Member
 
Join Date: Dec 2009
Posts: 296
Python script starts only from console

Hello,
I got into Python for some time and is a delight. I stumbled upon a small problem while beast. I created a very simple little game that works on hair, but the graphics were entirely within my script using commands create_line, create_rectangle, create_oval, etc. not knowing at the time how to work with pictures under Python. Now I duplicated the file of my game, and have replaced all my graphic part with calls to external images. Jpg and. Png. But since my script does not want to engage with the mouse, but only from the console. I have checked the file properties it was executable, but nothing works. Other scripts themselves, to throw out since my file browser. If someone has an idea? Thank you in advance.
Reply With Quote
  #2  
Old 11-01-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
Re: Python script starts only from console

Hello,
When you say run the script with the mouse, it's action that leads you to the window on which you have the choice between Show, Lancer, etc. ...? For my part, I always launch my scripts on the command line. I think I have not understood your exact problem, so if you explain more clearly then it would be more helpful to us.
Reply With Quote
  #3  
Old 11-01-2010
Member
 
Join Date: Dec 2009
Posts: 296
Re: Python script starts only from console

Hi
No, when I speak to run the script with the mouse, I spoke to execute my script by double-clicking its icon in the file manager, like to open a document for example. My script starts up via the terminal but not otherwise. The other scripts I created to launch them all too well "in graphic" only through the terminal.
Reply With Quote
  #4  
Old 11-01-2010
Member
 
Join Date: May 2008
Posts: 1,990
Re: Python script starts only from console

Hello,
If your program does not start per-click (or double-click depending on the settings), it is because he does not start in the correct folder (the one where your script) at once, it can not find your pictures and plant. In launching the console, you do not have this problem because the console is on file in your script. Your other scripts which they operate, must not use external files. The solution I use, at the beginning of each of my python programs I put these lines.
Quote:
import os, os.path, sys
HERE = os.path.dirname (sys.argv [0])
APPDIR = os.path.abspath (HERE)
sys.path.insert (0, APPDIR)
os.chdir (APPDIR)
This changes the current folder in the program, and I can use the files without error.
Reply With Quote
  #5  
Old 11-01-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
Re: Python script starts only from console

Hello,
Just go through these part of code
Code:
import os, os.path, sys
import of python modules needed
Code:
HERE = os.path.dirname (sys.argv [0])
recovery path python file (the one that starts) in the variable HERE
Code:
APPDIR = os.path.abspath (HERE)
Variable APPDIR well be the full path HERE
I'm not sure we need to go through rather than APPDIR HERE but good.
Reply With Quote
  #6  
Old 11-01-2010
opaper's Avatar
Member
 
Join Date: May 2008
Posts: 2,362
Re: Python script starts only from console

Hello
In addition for the above code, you can add this
Code:
sys.path.insert (0, APPDIR)
APPDIR is placed in the path. If there are personal to import modules, it can be useful.
Code:
os.chdir (APPDIR)
Here is what allows the script to run properly.
It changes the path system to be APPDIR.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Python script starts only from console"
Thread Thread Starter Forum Replies Last Post
Ubuntu crashes after deleting a python script... akhar Operating Systems 1 02-01-2010 09:55 AM
ComboFix Script and Recovery Console Zipp Windows Software 4 07-11-2009 02:27 PM
How to call perl script from Python? Jhonwho Software Development 3 23-07-2009 10:59 PM
Python starts slowly Bigga Lexx Software Development 2 10-01-2009 06:18 PM
Recovery Console Starts Without Prompting for a Password Plumdre Windows Server Help 4 06-08-2008 07:44 AM


All times are GMT +5.5. The time now is 12:13 PM.