Evaluating LLM Code Generation: Building a GUI Desktop Application from Scratch
This article presents a comprehensive evaluation of Large Language Models (LLMs) in generating runnable software, specifically a Python and tkinter desktop GUI application. It outlines a structured prompt engineering approach, deliberately introduces common engineering pitfalls such as UI thread blocking, and conducts a detailed assessment across requirement coverage, syntax verification, and threading model implementation. The results highlight the capabilities of current LLMs in defensive programming and complex task execution when provided with precise specifications, offering a reusable methodology for evaluating AI-generated code.
1. Background: From “Generating Code” to “Generating Runnable Software”
The programming capabilities of Large Language Models (LLMs) have improved significantly over the past two years. While mainstream models consistently achieve higher scores in public code generation benchmarks, high scores do not necessarily equate to usable outputs in actual engineering. For developers, three questions truly matter:
- Can the generated code pass compilation and syntax validation on the first try?
- Are all functional points listed in the requirements fully covered without omission?
- Does the code avoid engineering traps that textbooks often ignore but can easily render a program unusable?
To verify these three points, I designed a practical task of moderate complexity: writing a desktop batch video-to-audio extraction tool using Python and tkinter. This task involves file I/O, external command invocation, and GUI threading models, making it an ideal touchstone for testing a model’s comprehensive capabilities.
2. Requirement Design: Deliberately Creating “Killer Traps”
To ensure the test had sufficient differentiation, I avoided writing a vague prompt like “help me write a conversion tool” and instead broke down the constraints into fine details:
- Functional Layer: Support common video formats as input, export to mainstream audio formats like MP3 and WAV; provide a complete set of features including file import list, input/output format settings, execute conversion, and exit program.
- Engineering Layer: Must include a progress bar and a status bar; provide clear prompts when conversion errors occur.
- Performance Layer: The interface must not freeze, and the window must remain responsive during the conversion process.
“The interface must not freeze” is the most critical constraint. Anyone familiar with GUI programming knows that if time-consuming conversion logic is written directly into the main thread, tkinter’s event loop will be blocked, causing the window to immediately enter an “unresponsive” state. This serves as a touchstone to test whether the model genuinely understands the GUI event model rather than just applying templates—many lazy generation solutions will fail here.
3. Prompt Engineering: Translating Vague Needs into Executable Specs
The quality of the test results heavily depends on the prompt. I adopted a four-part structure: “Role + Tech Stack + Feature List + Quality Constraints”:
Role: You are a senior Python desktop application developer.Tech Stack: Python 3 + tkinter + ffmpeg (invoked via subprocess).Feature List:1. Support batch importing video files, displaying file names and status in a list;2. Provide input format recognition and a dropdown for target format selection (MP3/WAV, etc.);3. Display a progress bar during conversion, with a status bar outputting the current task in real-time;4. Prompt with a message box on error, without interrupting subsequent tasks.Quality Constraints:1. The conversion logic must be executed in a child thread, updating the UI via a queue;2. Check if ffmpeg is available when the program starts;3. Automatically append an index number to output files with duplicate names to avoid overwriting.
After sending this prompt to the AI coding assistant, the entire generation process was seamless: it first output the complete code, then self-checked the syntax, and finally attached a feature description. This “generation—self-validation—explanation” pipeline behavior indicates that the model has internalized basic engineering delivery awareness, rather than merely outputting a code snippet.
4. Result Evaluation: Acceptance Across Three Dimensions
4.1 Requirement Coverage
I cross-referenced the requirement list line by line. All functional points were implemented, and the model proactively filled in details I had not explicitly requested:
- Recursively scanning directories to automatically discover video files in subfolders;
- Completing a compatibility list for common video and audio formats;
- Automatically adding serial numbers to output files with the same name to prevent overwriting;
- Pre-checking the ffmpeg installation status before conversion and providing actionable prompts if it is missing.
This “beyond the literal requirements” behavior is essentially the defensive programming habits the model learned from massive open-source projects, which is a crucial indicator distinguishing “memorizing code” from “understanding engineering.”
4.2 Syntax and Run Verification
After saving, the code ran directly on the first try with zero errors. The interface layout was logical: the file list, format selection area, progress bar, and status bar were all correctly placed, and there were no common rookie mistakes (such as forgetting to call mainloop or leaving widgets un-gridded).
4.3 The Crucial Threading Model
I focused my review on how time-consuming tasks were implemented. The model adopted the standard “child thread + queue” pattern:
import threading, queuedef convert_worker(files, target_fmt, ui_queue):for i, f in enumerate(files):try:subprocess.run(["ffmpeg", "-i", f, os.path.join(out_dir, f"out_{i}.{target_fmt}")],check=True, capture_output=True)ui_queue.put(("progress", (i + 1) / len(files)))except subprocess.CalledProcessError as e:ui_queue.put(("error", f"{f} conversion failed"))ui_queue.put(("done", None))def poll_queue():try:kind, payload = ui_queue.get_nowait()# Update progress bar / status bar / message box promptexcept queue.Empty:passroot.after(100, poll_queue)
The child thread executes the conversion, while the main thread periodically polls the queue via after to refresh the UI—this is the correct approach for tkinter multithreaded programming, avoiding the risk of manipulating widgets directly across threads. The freezing issue was cleanly and efficiently circumvented.
5. Follow-up Verification: Reliability in Boundary Scenarios
After confirming the code was usable, I asked follow-up questions regarding boundary scenarios, such as “Where is the default output directory?” and “What happens if the file path contains spaces and special characters?” The model’s answers not only accurately pointed out the location of the default output logic but also proactively reminded me about path escaping. This demonstrates that the model possesses “contextual memory” regarding the generated code; follow-up questions do not require pasting the code again, making the engineering dialogue experience akin to pair programming with a colleague.
6. Conclusion: A Reusable Methodology for LLM Code Evaluation
Based on this practice, I have summarized four evaluation recommendations:
- Quantify Requirements: Translate adjectives like “user-friendly” and “runs smoothly” into verifiable hard clauses (e.g., “Conversion must execute in a child thread”).
- Deliberately Plant Traps: Include error-prone points in the requirements such as threading models, exception handling, and resource competition to test the model’s true proficiency.
- Verify Line by Line: After receiving the code, check it against the requirement list item by item, rather than just looking at whether it “can run.”
- Follow-up on Boundaries: Evaluate the model’s depth of control over its own code by asking follow-up questions about default behaviors, exception paths, and special inputs.
The conclusion is that the code generation capabilities of current mainstream LLMs are already sufficient for developing structured, small-to-medium-sized applications. As long as prompts are well-designed, generating code once with zero errors is not an accident. What truly determines success is whether the developer can translate vague requirements into precise, executable specifications for the model—this is a capability that remains irreplaceable by humans in the short term.
