Python文件可执行错误

时间:2016-04-26 14:40:11

标签: python executable cx-freeze

我为python游戏做了一个燃料计算器程序,然后用cx_Freeze编译成.exe。它将它很好地转换为.exe并且我可以打开可执行文件但是当脚本与用户交互时,当用户引入所请求的信息时按下回车后窗口关闭。 这是代码的一部分,在向用户请求一些信息后,程序进行了一些计算,但我认为这是无关紧要的,因为问题出在输入中。我希望当用户按下输入所请求信息的输入时程序不会关闭。

import sys

COMBUSTIBLE=chr(raw_input("Introduce unidad de combustible: "))
DURACION=chr(raw_input("Introduce unidad de duracion: "))

if COMBUSTIBLE != "litros" and COMBUSTIBLE != "kilos" and DURACION != "vueltas" and DURACION != "tiempo" and DURACION != "km":
    print "Error: Ambos argumentos son invalidos"
    print "Primer argumento debe ser 'litros' o 'kilos'"
    print "Segundo argumento debe ser 'tiempo' o 'vueltas' o 'km'"
    sys.exit(1)
elif COMBUSTIBLE != "litros" and COMBUSTIBLE != "kilos":
    print "Error: Primer argumento invalido"
    print "Primer argumento debe ser 'litros' o 'kilos'"
    sys.exit(2)
elif DURACION != "tiempo" and DURACION != "vueltas" and DURACION != "km":
    print "Error: Segundo argumento invalido"
    print "Segundo argumento debe ser 'tiempo' o 'vueltas' o 'km'"
    sys.exit(3)
else:
    pass

# TIPO 1 - LITROS - VUELTAS 
if COMBUSTIBLE == "l" and DURACION == "v":
    # DATA REQUEST
    RACE_DURATION=int(raw_input("Introduce el total de vueltas de la carrera: "))
    CAR_FUEL=float(raw_input("Introduce los litros totales del coche: "))
    FUEL_PER_LAP=float(raw_input("Introduce el consumo medio en litros por vuelta: "))

1 个答案:

答案 0 :(得分:0)

执行完程序后,窗口将立即关闭。因此,如果您希望窗口保持打开状态,则应删除sys.exit()语句并在脚本末尾添加一些内容,如:

input("Press any key to exit: ") 

在Python 3或

raw_input("Press any key to exit: ") 

在Python 2中