From 4eaf699a1e1052a3031a7d6359347461ec554de2 Mon Sep 17 00:00:00 2001 From: Simon <65854503+StopmotionSimonYT@users.noreply.github.com> Date: Sun, 31 Jul 2022 22:36:55 +0200 Subject: [PATCH] Add files via upload --- GUI.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 GUI.py diff --git a/GUI.py b/GUI.py new file mode 100644 index 0000000..90e37ae --- /dev/null +++ b/GUI.py @@ -0,0 +1,30 @@ +# Import the server module +import http.server +import webbrowser +# Set the hostname +HOST = "localhost" +# Set the port number +PORT = 4000 + +# Define class to display the index page of the web server +class PythonServer(http.server.SimpleHTTPRequestHandler): + def do_GET(self): + if self.path == '/GUI': + self.path = 'index.html' + return http.server.SimpleHTTPRequestHandler.do_GET(self) + +# Declare object of the class +webServer = http.server.HTTPServer((HOST, PORT), PythonServer) +# Print the URL of the webserver, new =2 opens in a new tab +print(f"Server started at http://{HOST}:{PORT}/GUI/") +webbrowser.open(f'http://{HOST}:{PORT}/GUI/', new = 2) +print("Website opened in new tab") +print("Press Ctrl+C to quit") +try: + # Run the web server + webServer.serve_forever() +except KeyboardInterrupt: + # Stop the web server + webServer.server_close() + print("The server is stopped.") + exit() \ No newline at end of file