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:
- I am working on a video tutorial but for the meantime here are the steps!
- Go to python.org and download the latest version
- Download the latest release and extract it in any folder you want it to live.
- If you don't want to type your ip in everytime follow these steps.
- For Windows - open cmd
- Do
ipconfig
- Find
ipv4 address : "YOUR IP ADDRESS"
- Remember this for later.
- Open main.py in any text editor.
- Locate the start_server(port, host, etc...) line.
- Change
host="192.168.1.80"
tohost="YOUR IP ADDRESS"
- Then locate line 427 or
host_label = ctk.CTkLabel(root, text="Enter host (optional, default: 192.168.1.80):")
- Change this into
host_label = ctk.CTkLabel(root, text="Enter host (optional, default: YOUR IP ADDRESS THAT YOU PUT IN HOST):")
- Important to mention put your actual ip address not "YOUR IP ADDRESS" because if you do it won't work.
- That's it for setting up your Ip
- Navigate to your folder for this directory in command prompt
- Do
pip install customtkinter
- That's it for setup
- MUST BE ADMIN
- ONLY FOR WINDOWS
- Same way as any other .exe
- The script imports a variety of libraries such as
random
,customtkinter
,http.server
,xml.etree.ElementTree
, and others. customtkinter
(CTk) is used for creating a modern styled GUI, whilehttp.server
handles the HTTP server functionality.- The code interacts with XML files, performs file operations, and supports a web-based front-end.
generate_random_port()
: This function generates a random port number between 8000 and 8080 for the server to run on.today
andformated_today
: These variables capture today's date and format it for later use in storing form responses.xml_lock
: A threading lock to safely access and modify XML data in a multi-threaded environment.
open_destroy_window()
andopen_read_window()
: These functions trigger thefile()
andcode()
functions from external modules to manage specific window functionalities like file destruction and reading.append_to_xml()
: This function appends user responses (name and answer) to an XML file, ensuring it’s well-formed and formatted.
- 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.
normUserHTTP
: This class extendsBaseHTTPRequestHandler
to define how GET and POST requests are handled:- GET: Serves the HTML page and static images (like flags).
- POST: Receives form data (name and answer), appends it to the XML file, and re-renders the page.
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.update_timer()
: This function counts down the specified time and shuts down the server when the time expires.
-
start_gui()
: This function creates and runs acustomtkinter
GUI. It allows users to:- Enter a question to be asked via the web server.
- Set the host address and timer duration.
- Start or stop the server with buttons.
- Display the current server status, IP, and port.
- Trigger actions for opening the destroy or read windows.
-
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.
- The served HTML page includes input fields for the user to submit their name and response. It uses JavaScript to:
- Store the user's input using AJAX (via
fetch
). - Dynamically resize the input field and update the word count.
- Display the remaining time on the page.
- Store the user's input using AJAX (via
- 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.
- Events:
stop_event
andshutdown_event
are used to control the server’s lifecycle and shut it down when necessary.
- 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.
- The
start_gui()
function is invoked when the script is run, which sets up the GUI and starts the interactive server process.
-
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. -
"guy who made this" notes Made by “EndToEndDev”
-
Total Updates (so far) : 457
-
Last Update Time : 6:58 P.m. 3/11/2025