Jump to content

python exit outside terminal

Enderg312

How do I exit a python program while out side of the terminal? I am trying to make a python program for a game but I can't seem to exit the program out side the terminal.

 

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, Enderg312 said:

How do I exit a python program while out side of the terminal? I am trying to make a python program for a game but I can't seem to exit the program out side the terminal.

 

exit()

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Enderg312 said:

Well I have a loop.

Use an if statement then.

if blah

   exit()

Link to comment
Share on other sites

Link to post
Share on other sites

I did use a if statement, I want to press w a s or d to exit the program. But for some reason it doesn't work.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Enderg312 said:

I did use a if statement, I want to press w a s or d to exit the program. But for some reason it doesn't work.

userinput = input("What would you like to do?")
if (userinput == "w"):
    exit()
if (userinput == "a"):
    exit()

 

Link to comment
Share on other sites

Link to post
Share on other sites

But will it work outside of the terminal like in a game or a web browser?

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Enderg312 said:

But will it work outside of the terminal like in a game or a web browser?

It should as long as it is in the loop.

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, Enderg312 said:

Well I tried it and it still didn't work.

Are you using python 2 or 3?

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Enderg312 said:

3 with pyautogui

Is your if statement in the loop? Like so:

while x = 1:
  #do stuff
  userinput = input("What would you like to do next?")
  if (userinput == "w"):
    exit()

 

Link to comment
Share on other sites

Link to post
Share on other sites

Yes but the program doesn't like the if part being in a tab line like your example.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Enderg312 said:

Yes but the program doesn't like the if part being in a tab line like your example.

The gui program?

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Enderg312 said:

Yeah.

I was thinking it would be similar but I personally haven't done anything with a gui in python. Hopefully someone else can help you.

Link to comment
Share on other sites

Link to post
Share on other sites

20 minutes ago, Enderg312 said:

Could you reach out to someone who could help?

I would if I knew anyone. Someone else will find this thread I've found a lot of help here.

Link to comment
Share on other sites

Link to post
Share on other sites

I got it working just downloaded another python library and fixed the problem.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×