Running a program by double-click (windows)

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: May 2008
Posts: 13
Reputation: Kabooom is an unknown quantity at this point 
Solved Threads: 3
Kabooom Kabooom is offline Offline
Newbie Poster

Running a program by double-click (windows)

 
0
  #1
May 25th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

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

 
0
  #2
May 25th, 2008
Actually, it probably does something and then closes the window immediately -- which means you can't see it!

Try this:

  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

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

 
0
  #3
May 25th, 2008
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.")
Should you find Irony, you can keep her!
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: Kabooom is an unknown quantity at this point 
Solved Threads: 3
Kabooom Kabooom is offline Offline
Newbie Poster

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

 
0
  #4
May 25th, 2008
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):

  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

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

 
0
  #5
May 25th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: Kabooom is an unknown quantity at this point 
Solved Threads: 3
Kabooom Kabooom is offline Offline
Newbie Poster

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

 
0
  #6
May 25th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

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

 
0
  #7
May 25th, 2008
OK, wait. In your source code directory, you have

myprog.pyw
myprog.pyc

Yes?

What happens if you double-click "myprog.pyw"?
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: Kabooom is an unknown quantity at this point 
Solved Threads: 3
Kabooom Kabooom is offline Offline
Newbie Poster

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

 
0
  #8
May 25th, 2008
Literally nothing so far as a I can tell.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 13
Reputation: Kabooom is an unknown quantity at this point 
Solved Threads: 3
Kabooom Kabooom is offline Offline
Newbie Poster

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

 
0
  #9
May 25th, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC