Hiding console window

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lucas Raab

    Hiding console window

    I'm looking to play a joke on a friend and I'm wondering if there's a way to
    not show or hide the DOS console. My friend doesn't have python so I have to
    compile it to an EXE.

    TIA


  • Peter Hansen

    #2
    Re: Hiding console window

    Lucas Raab wrote:
    [color=blue]
    > I'm looking to play a joke on a friend and I'm wondering if there's a way to
    > not show or hide the DOS console. My friend doesn't have python so I have to
    > compile it to an EXE.[/color]

    Use py2exe to compile Python programs to EXEs.

    You would need to define what "hide" means to you to get a useful answer
    to the first part of the question. I would just click on the "close"
    gadget in the upper right corner, if I wanted to "hide" a DOS console...

    -Peter

    Comment

    • Josef Meile

      #3
      Re: Hiding console window

      Peter Hansen wrote:[color=blue]
      > Lucas Raab wrote:
      >[color=green]
      >> I'm looking to play a joke on a friend and I'm wondering if there's a
      >> way to
      >> not show or hide the DOS console. My friend doesn't have python so I
      >> have to
      >> compile it to an EXE.[/color]
      >
      >
      > Use py2exe to compile Python programs to EXEs.
      >
      > You would need to define what "hide" means to you to get a useful answer
      > to the first part of the question. I would just click on the "close"
      > gadget in the upper right corner, if I wanted to "hide" a DOS console...
      >
      > -Peter[/color]
      I think there is a way of telling py2exe that the program is a windows
      exe, so you won't see the console. You just have to invoque the py2exe
      help. If I'm not wrong the option should be "--help" or "-h"


      Regards,
      Josef

      Comment

      • Otto Krüse

        #4
        Re: Hiding console window

        You can tell py2exe to make a windows exe by putting the line windows =
        ["yourscript .py"] in your setup.py script.


        Example:
        """
        # A setup script

        from distutils.core import setup
        import py2exe

        setup(windows = ["yourScript .py"])
        """


        What I'm wondering about now if there's a way to achieve the same for a
        python script (instead of the .exe version of that script). --> I want
        to double-click on a python Tkinter script and only see the GUI, not the
        console window behind it. Does anyone know how to do this?

        Regards,
        Otto



        Josef Meile wrote:[color=blue]
        > Peter Hansen wrote:
        >[color=green]
        >> Lucas Raab wrote:
        >>[color=darkred]
        >>> I'm looking to play a joke on a friend and I'm wondering if there's a
        >>> way to
        >>> not show or hide the DOS console. My friend doesn't have python so I
        >>> have to
        >>> compile it to an EXE.[/color]
        >>
        >>
        >>
        >> Use py2exe to compile Python programs to EXEs.
        >>
        >> You would need to define what "hide" means to you to get a useful
        >> answer to the first part of the question. I would just click on the
        >> "close" gadget in the upper right corner, if I wanted to "hide" a DOS
        >> console...
        >>
        >> -Peter[/color]
        >
        > I think there is a way of telling py2exe that the program is a windows
        > exe, so you won't see the console. You just have to invoque the py2exe
        > help. If I'm not wrong the option should be "--help" or "-h"
        >
        >
        > Regards,
        > Josef
        >[/color]

        Comment

        • Jørgen Cederberg

          #5
          Re: Hiding console window

          Otto Krüse wrote:[color=blue]
          > You can tell py2exe to make a windows exe by putting the line windows =
          > ["yourscript .py"] in your setup.py script.
          >
          >
          > Example:
          > """
          > # A setup script
          >
          > from distutils.core import setup
          > import py2exe
          >
          > setup(windows = ["yourScript .py"])
          > """
          >
          >
          > What I'm wondering about now if there's a way to achieve the same for a
          > python script (instead of the .exe version of that script). --> I want
          > to double-click on a python Tkinter script and only see the GUI, not the
          > console window behind it. Does anyone know how to do this?
          >[/color]

          The extension should pyw instead of py!

          Regards
          Jorgen

          Comment

          • Lucas Raab

            #6
            Re: Hiding console window


            "Lucas Raab" <pythongnome@ho tmail.com> wrote in message
            news:Xkh6c.8082 $GQ3.5678@newsr ead3.news.atl.e arthlink.net...[color=blue]
            > I'm looking to play a joke on a friend and I'm wondering if there's a way[/color]
            to[color=blue]
            > not show or hide the DOS console. My friend doesn't have python so I have[/color]
            to[color=blue]
            > compile it to an EXE.
            >
            > TIA
            >
            >[/color]

            In response to Peter's question, what I meant when I said hide was to hide
            the console while running the program. Essentially, it would run in the
            background. The application would run, but you wouldn't see any sign of it.
            In response to Jorgen and Josef, unfortunately it didn't work. Here's the
            code for it. It may be a little messy, but I wasn't aiming for perfection:

            import pygame
            import time

            def sleep():
            #Sleep for 5 minutes
            time.sleep(300)
            def play():
            #Initialize pygame
            pygame.init()
            #Initialize mixer
            pygame.mixer.in it()
            #Load and play sound1
            pygame.mixer.mu sic.load('C:/sound1.mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play hazards of retreating
            pygame.mixer.mu sic.load('C:/hazards_of_retr eating.mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play bring it on
            pygame.mixer.mu sic.load('C:/bring_it_on.mp3 ')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play freaked by flood
            pygame.mixer.mu sic.load('C:/freaked_by_floo d.mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play grunty thirst
            pygame.mixer.mu sic.load('C:/grunty_thirst.m p3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play joe has lost it
            pygame.mixer.mu sic.load('C:/joe_has_lost_it .mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play the french grunt
            pygame.mixer.mu sic.load('C:\th e_french_grunt. mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play stacker e3 outtake2
            pygame.mixer.mu sic.load('C:\st acker_e3_outtak e2.mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play poor running anatomy
            pygame.mixer.mu sic.load('C:\po or_running_anat omy.mp3')
            pygame.mixer.mu sic.play()
            sleep()
            #Load and play bring it on
            pygame.mixer.mu sic.load('C:\br ing_it_on.mp3')
            pygame.mixer.mu sic.play()
            #Quit playing and close pygame
            pygame.mixer.qu it()
            pygame.quit()

            #Start the program
            play()

            You may raise your eyebrows at the filenames, but as I said its a joke I'm
            playing. The sound clips are based off the game Halo. Just fill in your own
            files instead of mine.

            TIA


            Comment

            • Josef Meile

              #7
              Re: Hiding console window

              If you generate the exe with py2exe, then you could do:

              python setup.py py2exe -v -w

              Where setup.py is the setup script where you specify the
              python imports and your program modules. (see py2exe
              documentation). The "-w" option was the option I was
              talking before. I don't know if it produces the same
              effect of the proposed solution by Otto. With this option,
              you won't see a DOS console, however, I don't know if
              it will hide the icon on the task bar. Try to call the script
              on the "Startup" menu or with the "Scheduled Tasks" of
              windows or perhaps you will have to do it from the
              registry.
              [color=blue]
              > In response to Peter's question, what I meant when I said hide was to hide
              > the console while running the program. Essentially, it would run in the
              > background. The application would run, but you wouldn't see any sign of[/color]
              it.[color=blue]
              > In response to Jorgen and Josef, unfortunately it didn't work. Here's the
              > code for it. It may be a little messy, but I wasn't aiming for perfection:
              >
              > import pygame
              > import time
              >
              > def sleep():
              > #Sleep for 5 minutes
              > time.sleep(300)
              > def play():
              > #Initialize pygame
              > pygame.init()
              > #Initialize mixer
              > pygame.mixer.in it()
              > #Load and play sound1
              > pygame.mixer.mu sic.load('C:/sound1.mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play hazards of retreating
              > pygame.mixer.mu sic.load('C:/hazards_of_retr eating.mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play bring it on
              > pygame.mixer.mu sic.load('C:/bring_it_on.mp3 ')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play freaked by flood
              > pygame.mixer.mu sic.load('C:/freaked_by_floo d.mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play grunty thirst
              > pygame.mixer.mu sic.load('C:/grunty_thirst.m p3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play joe has lost it
              > pygame.mixer.mu sic.load('C:/joe_has_lost_it .mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play the french grunt
              > pygame.mixer.mu sic.load('C:\th e_french_grunt. mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play stacker e3 outtake2
              > pygame.mixer.mu sic.load('C:\st acker_e3_outtak e2.mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play poor running anatomy
              > pygame.mixer.mu sic.load('C:\po or_running_anat omy.mp3')
              > pygame.mixer.mu sic.play()
              > sleep()
              > #Load and play bring it on
              > pygame.mixer.mu sic.load('C:\br ing_it_on.mp3')
              > pygame.mixer.mu sic.play()
              > #Quit playing and close pygame
              > pygame.mixer.qu it()
              > pygame.quit()
              >
              > #Start the program
              > play()
              >
              > You may raise your eyebrows at the filenames, but as I said its a joke I'm
              > playing. The sound clips are based off the game Halo. Just fill in your[/color]
              own[color=blue]
              > files instead of mine.[/color]


              Comment

              Working...