943,865 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 2788
  • Python RSS
May 25th, 2008
0

Running a program by double-click (windows)

Expand Post »
Just starting Python and I have a question about how to run it just by double-clicking. With simple things like print "Hello World" the wait for user input clause can be added and it will run by double clicking and give the desired output, but when I try it with something that uses a window for example it will not. All I get is some compiled python file that does nothing. I don't really want to make an executable if possible since I'd think there'd be a way to do this without one.

Any help would be greatly appreciated since I want to begin on a little project and for it to make any sense I'd need it to start up by itself. I've been searching the forums but there are pages upon pages of people trying to make it into an executable or irrelevant information and I'm not quite sure what the proper keywords for this is. Sorry for the trivial question.
Similar Threads
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Kabooom is offline Offline
13 posts
since May 2008
May 25th, 2008
0

Re: Running a program by double-click (windows)

Actually, it probably does something and then closes the window immediately -- which means you can't see it!

Try this:

Python Syntax (Toggle Plain Text)
  1. print "Hello, World"
  2. raw_input("Press <Enter> to exit.")

If you double-click this, you should get output in a command prompt window.

Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
May 25th, 2008
0

Re: Running a program by double-click (windows)

Some editors like DrPython, UliPad, PyScripter, IDLE have internal output window that will stay open without the use of console wait line like raw_input("Press <Enter> to exit.")
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
May 25th, 2008
0

Re: Running a program by double-click (windows)

The raw_input part is what I meant by "wait for user input clause". Sorry for not being more clear, but this does not seem to work with some programs. Here's an example of a program I'm trying to do this with (got it as example code from one of the forums):

Python Syntax (Toggle Plain Text)
  1. # import all the Tkinter methods
  2. from Tkinter import *
  3.  
  4. # create a window frame
  5. frame1 = Tk()
  6. # create a label
  7. label1 = Label(frame1, text="Hello, world!")
  8. # pack the label into the window frame
  9. label1.pack()
  10.  
  11. frame1.mainloop() # run the event-loop/program

What would I have to do to code like this to make it double-clickable?
Last edited by Kabooom; May 25th, 2008 at 1:58 pm.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Kabooom is offline Offline
13 posts
since May 2008
May 25th, 2008
0

Re: Running a program by double-click (windows)

Two things:

(1) I can double-click on your program and get a nice little Hello, World window, along with the command-prompt window. Do you get something else?

(2) If you manually rename the file from "myprog.py" to "myprog.pyw", the command-prompt window will not come up.

Jeff
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
May 25th, 2008
0

Re: Running a program by double-click (windows)

Hmm maybe my install is bad then. Even by renaming it .pyw as I did before, all I get is a .pyc (Compiled Python File). Clicking on this does nothing but show a command prompt for an instant and it disappears. Are you also using Windows XP jrcagle?

EDIT: Oh and to note I get the .pyc file from both .py and .pyw

EDIT: And another thing to add... Code using wxPython works fine, but the examples with Tkinter do not. Didn't plan on using Tkinter anyway, but after clicking it a ton of times it looks like the command prompt says something isn't defined. Unless anyone has a reason for this I'll probably mark this as solved in a couple hours.
Last edited by Kabooom; May 25th, 2008 at 9:45 pm. Reason: added info
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Kabooom is offline Offline
13 posts
since May 2008
May 25th, 2008
0

Re: Running a program by double-click (windows)

OK, wait. In your source code directory, you have

myprog.pyw
myprog.pyc

Yes?

What happens if you double-click "myprog.pyw"?
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006
May 25th, 2008
0

Re: Running a program by double-click (windows)

Literally nothing so far as a I can tell.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Kabooom is offline Offline
13 posts
since May 2008
May 25th, 2008
0

Re: Running a program by double-click (windows)

Oh wow... I suppose the reason for it not working was simply because I named it Tkinter. When I renamed it TkinterHW it worked. Sorry for the trouble, and thanks for the help all (especially jrcagle).
Last edited by Kabooom; May 25th, 2008 at 11:25 pm.
Reputation Points: 10
Solved Threads: 3
Newbie Poster
Kabooom is offline Offline
13 posts
since May 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: If and Else
Next Thread in Python Forum Timeline: Fibonacci sequence





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC