0

Summary:

Windows User, that has python installed on his/her machine, double-clicks a (.py) or (.bat) file and it launches myapp.py in the Python Idle Shell.

Alternatively, the myapp.py is able to launch itself in Python Idle Shell after getting double clicked but that is probably not feasible.

More rambly (to prevent misunderstanding):

If someone wants to run a (.py) file via Python Idle Shell, they would right-click on the file > 'Edit with IDLE' > 'Run Module (F5)'. How can I run the (.py) file via Python Idle Shell with just double-clicking a (.py) file or (.bat) file?

Additional info

OS: Windows 7 (x64)

Python: 2.7

3
  • The IDLE shell would not be able to be used without modification (to my knowledge). You could make a .bat file with python myapp.py but it wouldn't use IDLE. Commented Jun 9, 2018 at 23:12
  • 1
    You could make a batch file that started idle and used it's -r command-line option to run the .py file. Here's the documentation on Idle's Command line usage. Commented Jun 10, 2018 at 1:58
  • 1
    @martineau You just answered my question. Do you want to post this as an answer or should I answer my question (and give you the credits obviously). Commented Jun 10, 2018 at 10:30

2 Answers 2

2

As I said in a comment, from the Command line usage section of the Python 2 Idle documentation it sounded like you could do it in a batch file by starting idle and passing it the -r file option to get it to run your script. (Note for Python 3, here's the Command line usage section.)

Today I had a chance to explore this further myself and can report that it does indeed appear to work. So now here's what I meant in more concrete terms.

The following batch file is what I used on my Windows 7 (x64) system with the 32-bit version Python 2.7.14 installed. You will likely have to tweak the file paths used in it to suit your own configuration.

idletest.bat

@echo on
python "C:\Python\Lib\idlelib\idle.py" -r "idletest.py"
pause
Sign up to request clarification or add additional context in comments.

Comments

-1

If Python is in your windows path, one way to interpret / “execute” myapp.py in Python via a batch script (.bat) could be :

Starter.bat :

@echo off
title “MyApp Launcher”
python2 myapp.py
pause
exit

However it does not specifically use the IDLE application ! Also the .bat must be in the same folder (or the path between both elements should be fixed) that myapp.py .

NB : Depending on your installation of Python, if it do not work, try replacing python2 by python or by py

1 Comment

As you said, this does not specifically use the IDLE application, therefore it's not what I am looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.