无法在 Visual Studio 2022 之外运行 Python 脚本,但在 Visual Studio 内运行正常

问题描述 投票:0回答:1

当我在 Visual Studio 2022 外部运行 Python 脚本时,黑色提示立即再次关闭,但当我在 Visual Studio 内部运行它时,它会按预期工作。

到目前为止,我只是尝试创建一个界面,您可以在其中通过使用箭头键进行选择来选择执行操作。

我尝试通过 cmd 并使用 python 3.10 和 3.7 运行脚本。

from turtle import clearscreen
import keyboard
import time
import os
import colorconsole
import sys



i = 0
def clear():
    os.system("cls")

def menue():
    if i == 0:
        print(" >", end="")
    print("bootloader programming")
    if i == 1:
        print(" >", end="")
    print("system controller programming")
    if i == 2:
        print(" >", end="")
    print("options")

menue()

while True:
    def bootloader():
        print("what bootloader do you require?")

    def systemController():
        print("what unit do you wish to program?")
    if keyboard.is_pressed('down'):
        i = i + 1
        if i == 3:
            i = 0
        clear()
        menue()
    elif keyboard.is_pressed('up'):
        i = i - 1
        if i == -1:
            i = 2
        clear()
        menue()
    elif keyboard.is_pressed('enter'):
        if i == 0:
            bootloader()
        if i == 1:
            systemController()
        if i == 2:
            options()

    time.sleep(0.1)


    def comConf():
        print("input desired COM-port and press enter")
        comDesire = input()

    def lockedConf():
        passwordInput = input("password:")
        if passwordInput == "supersecretpassword":
            print("welcome admin person")

    def options():
        i2 = 0

        def optionsMenue():
            if i2 == 0:
                print(" >", end="")
            print("back")
            if i2 == 1:
                print(" >", end="")
            print("select COM-port")
            if i2 == 2:
                print(" >", end="")
            print("locked config")

        optionsMenue()
        time.sleep(1)
        while True:
            if keyboard.is_pressed('down'):
                i2 = i2 + 1
                if i2 == 3:
                    i2 = 0
                clear()
                optionsMenue()
            elif keyboard.is_pressed('up'):
                i2 = i2 - 1
                if i2 == -1:
                    i2 = 2
                clear()
                optionsMenue()
            if keyboard.is_pressed('enter'):
                if i2 == 0:
                    clear()
                    menue()
                    break
                if i2 == 1:
                    comConf()
                if i2 == 2:
                    lockedConf()
            time.sleep(0.1)
python crash
1个回答
0
投票

尝试使用 python IDLE。如果在 Windows 上,请在搜索栏中搜索它。

© www.soinside.com 2019 - 2024. All rights reserved.