From what I understand, using sys.exit is not compatible with PyCharm and other IDEs, yet other exit methods that don't do garbage collection are not recommended. If I'm developing in PyCharm how can I properly shut down the program?
In the below example I am attempting to use a hot key to exit the program, yet the test statement is never reached. Is this an incorrect syntax or related to using the wrong exit command?
#Import modules
from tkinter import * #For images
from PIL import Image, ImageTk #For images
import os #For working directory
from pynput import keyboard #For hotkeys
#Set default directory
os.chdir('C:\\Users\\UserName\\Desktop\\Python\\SomeFolderName')
#Display Menu
root = Tk()
image = Image.open('menu.png')
display = ImageTk.PhotoImage(image)
root.overrideredirect(True) #Remove toolbar
label = Label(root, image=display)
label.pack()
root.mainloop()
#Functions
def ExitProgram():
print('test')
sys.exit(0)
#Define hotkeys
with keyboard.GlobalHotKeys({
'<ctrl>+w': ExitProgram,
'<ctrl>+0': ExitProgram}) as h:
h.join()