From 42e6042405f7b5791030ed0f127ea54fe8fa1e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abdulkadir=20Furkan=20=C5=9Eanl=C4=B1?= Date: Fri, 11 Jan 2019 12:53:06 +0100 Subject: [PATCH] Intuitivize exit sequence. --- ib-clearance.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ib-clearance.py b/ib-clearance.py index 5f3648e..0aed89e 100755 --- a/ib-clearance.py +++ b/ib-clearance.py @@ -17,6 +17,13 @@ import sqlite3 import time +from os import name + +# Import getch from msvcrt if running on Windows. +if name == "nt": + from msvcrt import getch +else: + from getch import getch def connect_database(file): @@ -145,7 +152,12 @@ def main(): else: print("\nStudent still has lessons, clearance not granted.") - if input("Enter y to run again.") not in ["y", "Y"]: + print("\nPress X key to exit, other key to run again.") + key = getch() + # msvcrt.getch returns type bytes, decode into str. + if isinstance(key, bytes): + key = key.decode() + if key.upper() == "X": break