{"id":20213629,"url":"https://github.com/endtoenddev/democracy-drive","last_synced_at":"2026-04-09T18:05:06.117Z","repository":{"id":262531976,"uuid":"887572993","full_name":"EndToEndDev/Democracy-Drive","owner":"EndToEndDev","description":"This code creates a Tkinter GUI to manage a web server. Users can submit their name and answer, which are stored in an XML file. The server runs in a separate thread, automatically shuts down when a timer ends, and displays server status. The GUI allows setting the question, host, and timer, with controls to start/stop the server.","archived":false,"fork":false,"pushed_at":"2025-01-06T21:03:19.000Z","size":620,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-03T10:44:50.453Z","etag":null,"topics":["clientside","css","html","js","python","serverside"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EndToEndDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-12T22:57:09.000Z","updated_at":"2025-01-06T21:03:22.000Z","dependencies_parsed_at":"2025-01-06T22:18:44.121Z","dependency_job_id":"4febf695-014b-4af7-acb0-4a74e3eb61d7","html_url":"https://github.com/EndToEndDev/Democracy-Drive","commit_stats":null,"previous_names":["endtoenddev/democracy-drive"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndToEndDev%2FDemocracy-Drive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndToEndDev%2FDemocracy-Drive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndToEndDev%2FDemocracy-Drive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EndToEndDev%2FDemocracy-Drive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EndToEndDev","download_url":"https://codeload.github.com/EndToEndDev/Democracy-Drive/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241652946,"owners_count":19997575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clientside","css","html","js","python","serverside"],"created_at":"2024-11-14T06:10:27.600Z","updated_at":"2025-12-31T01:05:48.998Z","avatar_url":"https://github.com/EndToEndDev.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"This Python code is a web server that integrates with a GUI using `customtkinter` and `tkinter` to facilitate interactive sessions with users. The main functionality revolves around running a web server that serves a form-based page where users can submit answers to a question. READ \"IMPORTANT INFORMATION FOR DOWNLOAD\" AND \"RUNNING main.py\". Below is a summary of the code's components:\n\n\n### 1. **IMPORTANT INFORMATION FOR DOWNLOAD**\n   - I am working on a video tutorial but for the meantime here are the steps!\n   - Go to python.org and download the latest version\n   - Download the latest release and extract it in any folder you want it to live.\n   - If you don't want to type your ip in everytime follow these steps.\n   - For Windows - open cmd\n   - Do `ipconfig`\n   - Find `ipv4 address :        \"YOUR IP ADDRESS\"`\n   - Remember this for later.\n   - Open main.py in any text editor.\n   - Locate the start_server(port, host, etc...) line.\n   - Change `host=\"192.168.1.80\"` to `host=\"YOUR IP ADDRESS\"`\n   - Then locate line 427 or `host_label = ctk.CTkLabel(root, text=\"Enter host (optional, default: 192.168.1.80):\")`\n   - Change this into `host_label = ctk.CTkLabel(root, text=\"Enter host (optional, default: YOUR IP ADDRESS THAT YOU PUT IN HOST):\")`\n   - Important to mention put your actual ip address not \"YOUR IP ADDRESS\" because if you do it won't work.\n   - That's it for setting up your Ip\n   - Navigate to your folder for this directory in command prompt\n   - Do `pip install customtkinter`\n   - That's it for setup\n\n### 2. **RUNNING main.exe**\n   - MUST BE ADMIN\n   - ONLY FOR WINDOWS\n   - Same way as any other .exe\n\n### 3. **Imports and Dependencies**\n   - The script imports a variety of libraries such as `random`, `customtkinter`, `http.server`, `xml.etree.ElementTree`, and others.\n   - `customtkinter` (CTk) is used for creating a modern styled GUI, while `http.server` handles the HTTP server functionality.\n   - The code interacts with XML files, performs file operations, and supports a web-based front-end.\n\n### 4. **Global Variables and Functions**\n   - **`generate_random_port()`**: This function generates a random port number between 8000 and 8080 for the server to run on.\n   - **`today` and `formated_today`**: These variables capture today's date and format it for later use in storing form responses.\n   - **`xml_lock`**: A threading lock to safely access and modify XML data in a multi-threaded environment.\n\n### 5. **Window and File Handling Functions**\n   - **`open_destroy_window()`** and **`open_read_window()`**: These functions trigger the `file()` and `code()` functions from external modules to manage specific window functionalities like file destruction and reading.\n   - **`append_to_xml()`**: This function appends user responses (name and answer) to an XML file, ensuring it’s well-formed and formatted.\n\n### 6. **HTTP Server Setup**\n   - **HTML Content**: The server serves an HTML page that includes a form where users can enter their name and answer to a question. The page also displays a timer, word count, and the server's IP and port.\n   - **`normUserHTTP`**: This class extends `BaseHTTPRequestHandler` to define how GET and POST requests are handled:\n     - **GET**: Serves the HTML page and static images (like flags).\n     - **POST**: Receives form data (name and answer), appends it to the XML file, and re-renders the page.\n\n### 7. **Server Functions**\n   - **`start_server()`**: This function sets up the HTTP server to listen on a dynamically generated port. It also handles form submissions by appending responses to an XML file and updating the webpage. It runs in a separate thread, allowing the GUI to stay responsive.\n   - **`update_timer()`**: This function counts down the specified time and shuts down the server when the time expires.\n\n### 8. **GUI Functions**\n   - **`start_gui()`**: This function creates and runs a `customtkinter` GUI. It allows users to:\n     - Enter a question to be asked via the web server.\n     - Set the host address and timer duration.\n     - Start or stop the server with buttons.\n     - Display the current server status, IP, and port.\n     - Trigger actions for opening the destroy or read windows.\n\n   - **Start and Stop Buttons**: The server can be started with the \"Start Server\" button, and it runs in a separate thread. The \"Stop Server\" button gracefully stops the server by setting the `stop_event` flag.\n\n### 9. **HTML and JavaScript for User Interaction**\n   - The served HTML page includes input fields for the user to submit their name and response. It uses JavaScript to:\n     - Store the user's input using AJAX (via `fetch`).\n     - Dynamically resize the input field and update the word count.\n     - Display the remaining time on the page.\n   \n### 10. **Threading and Concurrency**\n   - **Threads**: The server is run in a separate thread, allowing the GUI to remain interactive. The timer is also run in a separate thread to handle countdowns independently of the main server loop.\n   - **Events**: `stop_event` and `shutdown_event` are used to control the server’s lifecycle and shut it down when necessary.\n\n### 11. **Error Handling**\n   - The code includes error handling for various scenarios, such as missing files or server startup issues. If an error occurs, a message box is shown to inform the user.\n\n### 12. **Main Function**\n   - The `start_gui()` function is invoked when the script is run, which sets up the GUI and starts the interactive server process.\n\n### Summary:\n- The code defines a web-based interactive system where users can answer questions within a time limit. It serves a page with a question and inputs for the user's name and response. Upon submission, the answers are saved in an XML file. The system integrates a modern GUI using `customtkinter` and allows for real-time updates to the user interface, including a countdown timer, word count display, and server status. The server is designed to be started and stopped via the GUI.\n\n- \"guy who made this\" notes Made by “EndToEndDev” \n- Total Updates (so far) : 457\n- Last Update Time : 6:58 P.m. 3/11/2025\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendtoenddev%2Fdemocracy-drive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendtoenddev%2Fdemocracy-drive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendtoenddev%2Fdemocracy-drive/lists"}