Question

I've try everything I can do but still can't see my result on windows screen and stay. I don't want to use GUI and command prompt. here is my code.

only print('hello, world!') in hello.py

import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {"packages": ["os"], "excludes": ["tkinter"]}

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(name = "hello",
      version = "0.1",
      description = "the typical 'Hello, world!' script",
      options = {"build_exe": build_exe_options},
      executables = [Executable("hello.py")]          
      )

input('Press ENTER to continue')
Était-ce utile?

La solution

The script is compiling just fine. Your problem is the fact that the program runs too fast to see. It is displaying 'hello world', but because there is nothing to keep the program running the program exits and the window closes immediately after it begins. As Thomas K pointed out a simple solution is to add input() to the end of your hello.py script, in order to keep the program running until the user hits enter. Another option is to create a loop or something along those lines, but input() works just fine for keeping text displayed.

Hope this helped.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top