Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:19:06+00:00 2026-06-07T09:19:06+00:00

I have a program that runs in Python, without the console present (which is

  • 0

I have a program that runs in Python, without the console present (which is to say, I’ve compiled it using py2exe). I want people to be able to quit from the main menu, or by a particular key-press in-game (say, Shift+Q). I’m running it, for now, in Windows, though I am working on compiling Linux/Mac versions. Pressing the X button works if there’s no ‘while’ loop running, it seems, and that closes it correctly, otherwise it seems to ‘store’ the close command wait until the current loop is closed.

As for menu options, I’ve looked thoroughly through documentation and Stackoverflow and tried quit(), exit(), sys.exit() and every combination I can find, but every time I get:

Traceback (most recent call last):
  File "alphatime.pyw", line 61177, in <module>
  File "alphatime.pyw", line 53970, in place_menu
NameError: global name 'sys' is not defined

if I try sys.exit, and then:

Traceback (most recent call last):
  File "alphatime.pyw", line 61177, in <module>
  File "alphatime.pyw", line 53970, in place_menu
NameError: global name 'quit' is not defined

if I try just “quit()”. I’ve heard about ‘Raising’ things like a need to close the program, but I’m not clear what that means (I’m new to Python) and how I would go about doing that.

So, my question is two-fold.

Firstly, is there something I can put in loops for recognizing keypresses something that will recognize the ‘X’ being clicked, and close?

Secondly, is there an appropriate command that will just close the program? I cannot figure out why these commands don’t work, and I’ve had quite a few complaints from people using the program that it crashes, or they have to ctrl-alt-del it, or whatever. I believe

import os
try:
  os._exit(return_code)
except:
  pass

would work, but at this point, I’m not sure I’m competent enough at python to deploy it appropriately. Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:19:08+00:00Added an answer on June 7, 2026 at 9:19 am

    did you by any chance

    import sys
    

    because that should work!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that runs a program, which generates few .exe files
I have program that runs fast enough. I want to see the number of
I have a Java program that runs on my Ubuntu 10.04 machine and, without
So I have a Linux program that runs in a while(true) loop, which waits
I have a software that runs on mac (using terminal program) the program is
I have a cgi python program which runs an os.system command and this command
I have a Python program that runs a series of experiments, with no data
I have a program that runs in Python 2 and Python 3, but there
I have a Python program that spawns many threads, runs 4 at a time,
So I have a python script that runs a loop in which it calls

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.